DSA Algorithm Cheat Sheet
Arrays
- Prefix Sum
- Sliding Window
- Two Pointer Technique
- Kadane's Algorithm (Max Subarray Sum)
- Dutch National Flag (3-way partitioning)
Linked Lists
- Reverse a linked list (iterative & recursive)
- Detect cycle (Floyd's algorithm)
- Merge two sorted lists
- Find middle (Tortoise & Hare)
- Remove N-th node from end
- Intersection of two lists
- Clone list with random pointer
Trees
- DFS / BFS
- Diameter of Tree
- Lowest Common Ancestor (LCA)
- Height / Depth of tree
- Balanced Tree Check
- Tree to DLL conversion
- Serialize/Deserialize Binary Tree
Graphs
- DFS, BFS
- Dijkstra's Algorithm
- Bellman-Ford
- Floyd-Warshall
- Topological Sort (DFS/Kahn's)
- Union-Find (Disjoint Set)
- Kruskal's Algorithm
- Prim's Algorithm
- Tarjan's & Kosaraju's (SCC)
Sorting Algorithms
- Bubble Sort - O(n²)
- Selection Sort - O(n²)
- Insertion Sort - O(n²)
- Merge Sort - O(n log n)
- Quick Sort - O(n log n)
- Heap Sort - O(n log n)
- Counting Sort
- Radix Sort
- Bucket Sort
Searching Algorithms
- Linear Search - O(n)
- Binary Search - O(log n)
- Lower/Upper Bound
- Binary Search on Answer
- Ternary Search
- Hashing - O(1) avg
Dynamic Programming
- Fibonacci
- 0/1 Knapsack
- Unbounded Knapsack
- LCS (Longest Common Subsequence)
- LIS (Longest Increasing Subsequence)
- Matrix Chain Multiplication
- Partition Equal Subset Sum
- Edit Distance
- DP on Trees
- Bitmask DP