Advanced Algorithms: Sorting, Graphs, and Dynamic Programming
Lesson Promise
By the end of this lesson, you will understand how merge sort divides and conquers in O(n log n), how BFS and DFS traverse graphs through adjacency lists, and how dynamic programming turns exponential recursion into linear or polynomial time.
Narration Draft
Part 1 — Sorting and Binary Search (6:00) Review binary search on a sorted array: O(log n) by halving the search space each step. Then show merge sort: recursively split the array in half, sort each half, merge back. Trace the division producing single-element arrays, then the merge rebuilding sorted arrays.
Part 2 — Hash Tables and Trees (5:00) Recap hash table collision handling. Trace a hash table lookup through a collision chain. Then review tree traversals — inorder, preorder, postorder — and how recursion naturally maps to tree structure.
Part 3 — Graph Traversal (7:00) A graph is a set of nodes with edges between them. Show adjacency list representation. Trace BFS using a queue (level-order): visit node, enqueue neighbors. Trace DFS using a stack (recursive): visit node, recurse into unvisited neighbor.
Part 4 — Dynamic Programming (7:00) Dynamic programming solves problems with overlapping subproblems by caching results. Start with the climbing stairs problem: ways(n) = ways(n-1) + ways(n-2). Show the naive recursive tree (exponential), then the memoized version (O(n)), then the bottom-up version. Trace the computation table filling left to right.
Part 5 — Common Patterns (5:00) Sliding window, two pointers, prefix sums, union-find. Show how each pattern applies to its canonical problem.
Visual Sequence
- Binary search: highlight the shrinking search window halving each step
- Merge sort: divide tree showing 8 → 4 → 2 → 1, then merge animations
- BFS on a graph: queue animation, level-by-level node discovery
- DFS on a graph: recursive descent, stack unwinding, backtracking
- DP table: climbing stairs, show the table filling left to right
Companion Material
Related articles
Algorithms Are Procedures With Costs
Learn to connect an algorithm's correctness argument to the comparisons, branches, and memory accesses it performs.
Arrays and Memory: How Indexing Works
Why array indexing is O(1), how the CPU computes element addresses, and what spatial locality means for performance.
Recursion: Functions Calling Themselves
How a function can solve a problem by delegating a smaller version of the same problem to itself, the call stack, and common pitfalls.
More in Programming & Algorithms
Learning Algorithms from Scratch
A beginner-friendly walkthrough of what an algorithm is, how arrays store data in memory, and how simple search and insertion traces execute.
DetailsData Structures and Algorithms: From Arrays to Trees
Master arrays, hash tables, trees, and recursion through execution traces that show what actually happens in memory.
DetailsWhy Big-O Does Not Predict Every Run
A planned visual lesson connecting algorithmic growth to input shape, memory access, branches, and measured runtime.
DetailsNew lessons by email
Get new articles and notes on the systems behind everyday software.
One technical dispatch per week. No noise.
Not started
Sign in to save your learning progress.