📚 Data Structures

Data Structure Operation Worst Case Average Case Notes
Array / Dynamic Array Access O(1) O(1) Direct index arithmetic
Search O(n) O(n) Linear scan
Insert/Delete at end O(n) O(1) amortised Occasional resize cost
Insert/Delete at arbitrary pos O(n) O(n) Shifting elements
Singly Linked List Access / Search O(n) O(n) Node‑by‑node traversal
Insert/Delete at head O(1) O(1) Reassign head pointer
Insert/Delete at tail O(n) O(n) Unless a tail reference is maintained
Doubly Linked List Access / Search O(n) O(n)
Insert/Delete given node O(1) O(1) Pointer surgery with prev/next
Stack (array‑backed) Push / Pop O(1) O(1)
Queue (array or list) Enqueue / Dequeue O(1) O(1)
Hash Table (Map / dict) Search / Insert / Delete O(n) O(1) average Pathological collisions
Binary Search Tree (BST) Search / Insert / Delete O(n) O(log n) average Depends on balance
Balanced BST (AVL, R‑B) Search / Insert / Delete O(log n) O(log n) Strict rebalancing
Binary Heap Access Min/Max O(1) O(1) Root is extremum
Insert / Remove Min/Max O(log n) O(log n) Percolate up/down
Build Heap (Floyd’s) O(n) O(n) Bottom‑up heapify
Graph (Adj. List) BFS / DFS O(V + E) O(V + E) Visit every vertex & edge
Check adjacency O(deg(v)) O(deg(v)) Scan neighbour list
Graph (Adj. Matrix) BFS / DFS O(V²) O(V²) Matrix scan dominates
Check edge O(1) O(1) Direct lookup
Iterate neighbours O(V) O(V) Row scan
Skip List Search / Insert / Delete O(n) O(log n) average Probabilistic multi‑level links
B‑Tree (order m) Search / Insert / Delete O(log n) O(log n) Wide fan‑out for disk/system I/O
Disjoint Set Union (Union–Find)
find / union
O(Îą(n))
O(1) amortised
Îą(n) is inverse Ackermann (practically constant with path compression & union by rank)

🚀 Algorithms & Paradigms

Paradigm / Pattern Typical Task Time Complexity (rough) When to Use / Notes
Divide & Conquer e.g. merge sort, fast exponentiation O(n log n), O(log n) Split problem in half, recurse, then combine
Binary Search search sorted array / answer space O(log n) must have monotonic or sorted property
Two Pointers pair sums, reverse array, linked lists O(n) one head & tail (or slow/fast) to meet in middle
Sliding Window longest substring, subarray sums O(n) dynamic window adjust—“expand/contract”
Prefix Sum / Difference Array range-sum queries, subarray sums O(1) per query after O(n) precompute cumulative totals
Monotonic Stack / Queue Next Greater Element, sliding window O(n) maintain increasing/decreasing order
Backtracking (permutations) generate all orderings O(n·n!) n! leaves × O(n) build cost
Backtracking (subsets / combinations) enumerate subsets or k-combos O(2ⁿ¡n) or O(C(n,k)¡k) explore include/exclude branches
Dynamic Programming knapsack, LIS, edit distance depends on states (e.g. O(n²)) memo/tabulate overlapping subproblems
Greedy Algorithms interval scheduling, coin change O(n log n) or O(n) make locally optimal choices
Graph Traversal (BFS/DFS) connectivity, bipartiteness O(V+E) use adjacency list for sparse graphs
Shortest Paths Dijkstra, Bellman–Ford O(E log V), O(V·E) weighted graphs
Minimum Spanning Tree Kruskal, Prim O(E log E) use DSU or priority queue
Union–Find (DSU) connectivity, cycle detection O(α(n)) amortised path compression + union by rank
Bit Manipulation bitwise ops, masks, subset tricks O(1) per op xor/swaps, subset-iteration via mask & -mask
Randomization reservoir sampling, shuffle O(n) when unbiased sampling is needed
String Hashing (Rabin–Karp) substring search, duplicate detection O(n) average rolling hash + mod arithmetic
Math & Number Theory gcd/lcm, modular exp, primes O(log n) per op when problems involve divisibility or cycles

📚 Data Structures Section (reminder of key additions)


Next Steps

With those tweaks, you’ll have one of the most comprehensive, scan-friendly cheat sheets out there!