12)The DSA Cheat Sheet: 11 Essential Pattern Tables (Time & Space Complexity Included)

I have compiled the essence of all 11 topics into a single Grand Unified Strategy Document. This is what students should print and stick on their walls 24 hours before their interview.

“Students, stop memorizing code. Memorize the Pattern.

If you know which tool to use, the code writes itself.

Here is the decision matrix for every single data structure we have covered.”


“Students, efficiency is not just about speed; it’s about memory. A solution that uses $O(N)$ memory crashes on large datasets. A solution that uses O(1) memory scales infinitely. Here is the ultimate complexity reference for every pattern we covered.”

1. Array Patterns

The Art of Pointers & Windows.

Problem SignalThe Algorithm StrategyTime ComplexitySpace Complexity
Sorted Array + Target SumTwo Pointers (Converge)O(N)O(1)
Contiguous Subarray + Max/MinSliding WindowO(N)O(1)
Contiguous Sum (Negatives)Kadane’s AlgorithmO(N)O(1)
Range Queries (Sum of L…R)Prefix Sum ArrayO(1) QueryO(N)
Input range is 1 to NCyclic SortO(N)O(1)
Sort 3 Unique NumbersDutch National FlagO(N)O(1)
Find Majority (> N/2)Moore’s VotingO(N)O(1)
Rotated Sorted ArrayBinary SearchO(log N)O(1)

2. String Patterns

Text Processing & Hashing.

Problem SignalThe Algorithm StrategyTime ComplexitySpace Complexity
Palindrome / ReverseTwo PointersO(N)O(1)
Anagram / PermutationHash Map / Frequency ArrO(N)O(1) (26 chars)
Substring w/o RepeatsSliding Window + SetO(N)O(26) or O(N)
Pattern SearchKMP AlgorithmO(N+M)O(M) (LPS Array)
Prefix Search / AutocompleteTrie (Prefix Tree)O(L) (Length)O(N times 26)
Longest Palindromic SubstrExpand CenterO(N^2)O(1)
Longest Palindromic SubstrManacher’s AlgoO(N)O(N)

3. Linked List Patterns

Pointer Surgery (Always aim for O(1) Space).

Problem SignalThe Algorithm StrategyTime ComplexitySpace Complexity
Cycle DetectionFloyd’s (Slow/Fast)O(N)O(1)
Find Middle NodeSlow/Fast PointersO(N)O(1)
Intersection PointSwitch HeadsO(N+M)O(1)
Reverse List3-Pointer IterativeO(N)O(1)
Reverse ListRecursiveO(N)O(N) (Stack)
Merge Sorted ListsDummy NodeO(N+M)O(1)
Deep Copy (Random Pointer)Interleaving MethodO(N)O(1)

4. Stack & Queue Patterns

Ordering & Processing.

Problem SignalThe Data StructureTime ComplexitySpace Complexity
Nested Brackets / UndoStackO(N)O(N)
Next Greater ElementMonotonic StackO(N)O(N)
Sliding Window MaxMonotonic DequeO(N)O(K) (Window)
Level-by-LevelQueue (BFS)O(N)O(W) (Width)
LRU CacheDoubly Linked List + MapO(1) OpsO(Capacity)

5. Heap & Priority Queue Patterns

Selection & Scheduling.

Problem GoalWhich Heap?Time ComplexitySpace Complexity
Find K-LargestMin-Heap (Size K)$O(N \log K)$$O(K)$
Find K-SmallestMax-Heap (Size K)$O(N \log K)$$O(K)$
Merge K Sorted ListsMin-Heap (Values)$O(N \log K)$$O(K)$
Median of StreamMax (Left) + Min (Right)$O(\log N)$$O(N)$
Task SchedulingMax-Heap (Frequency)$O(N)$$O(26) \approx O(1)$

6. Greedy Patterns

Optimization Shortcuts.

Problem TypeStrategyTime ComplexitySpace Complexity
Max Activities / MeetingsSort (End Time)$O(N \log N)$$O(1)$
Fractional KnapsackSort (Ratio)$O(N \log N)$$O(1)$
Min PlatformsSort (Arrival/Depart)$O(N \log N)$$O(1)$
Huffman CodingMin-Heap$O(N \log N)$$O(N)$

7. Tree & BST Patterns

Hierarchy & Navigation.

Problem GoalStrategyTime ComplexitySpace Complexity
Path / HeightDFS (Recursion)$O(N)$$O(H)$ (Height)
Level Order ViewBFS (Queue)$O(N)$$O(W)$ (Width)
Sorted Data / Kth SmallestInorder Traversal$O(N)$$O(H)$
Common AncestorLCA Logic$O(N)$$O(H)$
Hard OptimizationMorris Traversal$O(N)$$O(1)$
Construct TreePreorder + Inorder Map$O(N)$$O(N)$

8. Graph Patterns

Connections & Networks.

Problem GoalThe AlgorithmTime ComplexitySpace Complexity
Shortest Path (Unweighted)BFS$O(V+E)$$O(V)$
Shortest Path (Weighted)Dijkstra$O(E \log V)$$O(V)$
Shortest Path (Negative)Bellman-Ford$O(VE)$$O(V)$
Detect CycleDFS + Recursion Stack$O(V+E)$$O(V)$
ConnectivityUnion-Find (DSU)$O(E \alpha(V))$$O(V)$
Dependency / SchedulingTopo Sort (Kahn’s)$O(V+E)$$O(V)$
Minimum Wire Cost (MST)Prim’s / Kruskal’s$O(E \log V)$$O(V)$

9. Recursion & Backtracking Patterns

The Decision Tree.

Problem SignalStrategyTime ComplexitySpace Complexity
Subsets / Power SetPick vs Don’t Pick$O(2^N)$$O(N)$
PermutationsSwap & Undo$O(N!)$$O(N)$
Maze / Word SearchFlood Fill (DFS)$O(4^{NM})$$O(NM)$
Sudoku / N-QueensIsSafe() + Try NextExponential$O(N^2)$ (Grid)

10. Dynamic Programming Patterns

Recursion + Memory.

Pattern NameFormulaTime ComplexitySpace Complexity
Fibonacci / Stairsdp[i-1] + dp[i-2]$O(N)$$O(1)$ (Optimized)
Grid Pathsdp[top] + dp[left]$O(RC)$$O(C)$ (Optimized)
LIS (Increasing)max(dp[i], 1+dp[j])$O(N^2)$$O(N)$
0/1 Knapsackmax(Excl, Val+Incl)$O(NW)$$O(W)$ (Optimized)
LCS (Strings)1+diag or max(up, left)$O(NM)$$O(M)$ (Optimized)

11. Bit Manipulation & Math Patterns

Hardware Optimization.

Problem GoalThe FormulaTime ComplexitySpace Complexity
Odd Occurrence (Unique)Result ^= Num$O(N)$$O(1)$
Check Power of 2(n & (n-1)) == 0$O(1)$$O(1)$
Count Set Bitsn = n & (n-1)$O(\text{Set Bits})$$O(1)$
GCD (HCF)gcd(b, a % b)$O(\log N)$$O(\log N)$ (Stack)
Primes (Range)Sieve of Eratosthenes$O(N \log \log N)$$O(N)$

Professor’s Final Exam Tip

“Students, notice how Two Pointers and Bit Manipulation are always O(1) Space?

If the interviewer says ‘Optimize for Space’, run to those two patterns immediately.

“If you are blank in an interview:

  1. Can I sort it? (Two Pointers)
  2. Can I use a Map? (Hashing)
  3. Is it a tree/graph? (BFS/DFS)
  4. Is it optimization? (DP/Greedy)

“Students, notice how Two Pointers and Bit Manipulation are always O(1) Space? If the interviewer says ‘Optimize for Space’, run to those two patterns immediately.

Start Brute Force, then apply the pattern. Good luck.”

Good luck. You are now ready.”

12)The DSA Cheat Sheet: 11 Essential Pattern Tables (Time & Space Complexity Included)

DSA Cheat Sheet, Coding Interview Patterns, Time and Space Complexity Chart, Algorithm Revision Sheet

YouTube Channels:
Trendy VS Vlogs
VS Coding Academy

Join Our WhatsApp Channel for the latest job opportunities and updates:
VS_CODING_ACADEMY WhatsApp Channel

Join Our Telegram Channel for the latest job opportunities and updates: https://t.me/vscodingacademy

Open our site in Telegram Bot: https://t.me/vscodingacademy_bot

For DSA Guide: https://vscodingacademy.com/category/dsa-guide/

Leave a Comment