DSA Quick Revision Notes
1. Basics & Complexity
Big-O complexities (common): O(1) < O(log n) < O(n) < O(n log n) < O(n^2) < O(2^n) < O(n!).
Array Access: O(1), Search: O(n) or O(log n) if sorted, Insert/Delete: O(n).
2. Arrays & Strings
Binary Search: O(log n).
Sliding Window: used for subarray problems (max sum, distinct chars).
Sorting: QuickSort Avg O(n log n), Worst O(n^2); MergeSort O(n log n).
3. Recursion & Backtracking
Factorial, Fibonacci recursion basics.
Backtracking: generate subsets, permutations, N-Queens.
4. Linked List
Reverse a Linked List: Iterative & Recursive O(n).
Cycle Detection: Floyd’s Cycle Algorithm (Tortoise & Hare).
Merge two sorted lists: O(n+m).
5. Stacks & Queues
Stack apps: Balanced Parentheses, Next Greater Element.
Queue apps: BFS traversal.
Deque: for sliding window maximum.
6. Trees
Traversals: Inorder, Preorder, Postorder, Level Order (BFS).
BST: Inorder traversal gives sorted order.
Lowest Common Ancestor (LCA) in O(h).
7. Graphs
Graph Traversals: BFS (queue), DFS (stack/recursion).
Dijkstra’s Algorithm: shortest path in weighted graph.
Union Find (Disjoint Set): cycle detection in O(alpha(n)).
8. Dynamic Programming
Classic DP: Fibonacci, Knapsack, LIS, Matrix Min Path.
DP State Design → define dp[i] clearly.
Memoization (Top-Down) vs Tabulation (Bottom-Up).
9. Greedy
Activity Selection Problem → earliest finishing first.
Huffman Coding for data compression.
10. Misc (Math & Bits)
GCD → Euclidean Algorithm O(log n).
Fast Power (Binary Exponentiation).
Bit Tricks: check odd/even (n & 1), swap (XOR), subsets (1<<n).