Ὅ DSA Handwritten-Style Notes (C++)
✏ Basics
● Time Complexity: O(1) < O(log n) < O(n) < O(n log n) < O(n^2)
● Space Complexity measures memory usage.
● STL Quick: vector, map, set, stack, queue.
✏ Arrays & Strings
● Two Pointer: Start and end indices move towards each other.
● Sliding Window: Fixed/variable size window to optimize loops.
● Common Qs: Reverse array, rotate array, max subarray sum.
✏ Searching & Sorting
● Binary Search: O(log n), works on sorted arrays.
● Sorting: QuickSort (O(n log n)), MergeSort (O(n log n)), BubbleSort (O(n^2)).
● Upper Bound / Lower Bound usage in C++ STL.
✏ Hashing
● map/unordered_map store key-value pairs.
● set/unordered_set store unique elements.
● Useful for frequency counting and lookups.
✏ Stack & Queue
● Stack: LIFO (last in, first out).
● Queue: FIFO (first in, first out).
● Applications: Expression evaluation, BFS.
✏ Linked List
● Singly LL: Node with data + next.
● Doubly LL: Node with data + prev + next.
● Common Qs: Reverse LL, detect cycle (Floyd’s algo).
✏ Recursion & Backtracking
● Recursion: Function calls itself.
● Base Case + Recursive Case.
● Backtracking: Undo choices to explore all solutions.
✏ Trees & BST
● Tree Traversals: Inorder, Preorder, Postorder.
● BST: Left < Root < Right.
● Common Qs: Height of tree, Lowest Common Ancestor.
✏ Graphs
● BFS: Level-order traversal.
● DFS: Depth-first traversal.
● Graph Representations: Adjacency list/matrix.
✏ Dynamic Programming Basics
● Break problem into subproblems, store results.
● Memoization (top-down) vs Tabulation (bottom-up).
● Common Qs: Fibonacci, Knapsack, Coin Change.