Algorithm Modules
Choose a Topic
📊

Sorting Algorithms

All 8 major sorts: Bubble, Selection, Insertion, Merge, Quick, Heap, Counting, Radix. Know which to use when.

Best: O(n log n)Space: O(1)–O(n)
🔍

Binary Search

Search in O(log n). But it's not just for sorted arrays — works on monotonic functions, rotation, and boundaries.

O(log n)Space: O(1)
🔄

Recursion

Solving problems by breaking them into smaller versions of themselves. Call stack, base cases, and recursion trees.

VariesSpace: O(n) stack
🧮

Dynamic Programming

The hardest and most rewarding technique. Memoization + tabulation. Coin Change, LCS, Knapsack, and 50+ patterns.

O(n²) → O(n)Space: O(n)
💰

Greedy Algorithms

Always pick the locally optimal choice. When it works, it's elegant and fast. Activity Selection, Huffman, Jump Game.

Usually O(n log n)Space: O(1)
🔙

Backtracking

Explore all possibilities and backtrack when stuck. N-Queens, Sudoku Solver, Permutations, Subsets, Word Search.

O(2ⁿ) or O(n!)Space: O(n)
✂️

Divide & Conquer

Split the problem, solve subparts, merge results. Merge Sort, Quick Sort, Binary Search, POW(x,n), and more.

O(n log n)Space: O(log n)
Quick Reference
Sorting Algorithm Comparison
Algorithm
Best
Average
Worst
Space
Bubble Sort
O(n)
O(n²)
O(n²)
O(1)
Insertion Sort
O(n)
O(n²)
O(n²)
O(1)
Selection Sort
O(n²)
O(n²)
O(n²)
O(1)
Merge Sort
O(n log n)
O(n log n)
O(n log n)
O(n)
Quick Sort
O(n log n)
O(n log n)
O(n²)
O(log n)
Heap Sort
O(n log n)
O(n log n)
O(n log n)
O(1)
Counting Sort
O(n+k)
O(n+k)
O(n+k)
O(k)
Radix Sort
O(nk)
O(nk)
O(nk)
O(n+k)
Dynamic Programming Roadmap
The 5 Steps to Crack DP
01

Identify the DP pattern

Does the problem ask for max/min/count of ways? Do choices affect future choices? If yes — likely DP.

Keywords: "maximum", "minimum", "number of ways", "can you reach"
02

Define the state

What does dp[i] represent? This is the hardest step. Be explicit: "dp[i] = max sum of subarray ending at index i"

dp[i][j] = min cost to reach cell (i,j)
03

Write the recurrence

How does dp[i] relate to dp[i-1] or smaller subproblems? This is your transition formula.

dp[i] = max(dp[i-1] + arr[i], arr[i]) ← Kadane's
04

Base case

What's the smallest subproblem you can answer directly without recursion?

dp[0] = arr[0] (first element is its own max subarray)
05

Bottom-up or Top-down?

Top-down = recursion + memoization (easier to write). Bottom-up = iterative table (usually more efficient).

Both are equivalent. Start with top-down for understanding.
Decision Guide
Which Algorithm Do I Reach For?

Start from what the problem is asking, not from the algorithm you know best. Click a leaf to jump to that module.

What is the problem asking? Find a target in a sorted array / monotonic space? Need order first — intervals, pairs, k-th element? Max / min / count ways over a sequence of choices? Enumerate every valid configuration? Splits into independent halves, cheap combine? Binary Search Sorting Backtracking Divide & Conquer Is the locally best choice provably always safe? yes no Greedy Dynamic Programming Everything here is built on Recursion — if the structure is self-similar, write the recursive form first.
← Phase 2: Data Structures Phase 4: Advanced →