Recursion & Divide and Conquer
Write correct recursive functions, reason about them by induction, and derive their cost from a recursion tree.
4 objectives 6 steps about 120 min
Check what you know
The lessons are coming later. The knowledge check is ready now.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Write recursive functions with explicit base cases and argue correctness and termination by induction on input size.
- Trace the call stack of a recursive function, explain Python's recursion limit, and rewrite deep recursion iteratively with an explicit stack.
- Solve a problem by divide and conquer and derive its running time from a recursion tree, for example T(n) = 2T(n/2) + O(n).
- Solve divide-and-conquer recurrences of the form T(n) = aT(n/b) + f(n) with the master theorem, and fall back to a recursion tree or a direct sum for forms it does not cover, such as T(n) = T(n - 1) + O(n).
Lesson plan
6 steps, about 120 min · 0 of 5 lessons available so far
- Trust the Smaller Problem Concept · 20 min · coming later
- Watching Frames Pile Up Worked example · 20 min · coming later
- Lab: When Recursion Goes Too Deep Lab · 20 min · coming later
- Split, Solve, Combine Worked example · 25 min · coming later
- Recursion Trees and Recurrences Concept · 20 min · coming later
- Check: Tracing and Costing Recursion Knowledge check · 8 questions
Practise it
Implement fast exponentiation, flattening of an arbitrarily nested list (recursive and explicit-stack versions), and maximum subarray sum by divide and conquer; for each, write a short induction argument and the recurrence with its solution. Then classify six recurrences with the master theorem, or explain why it does not apply, and confirm two of them by counting calls.
Build it from scratch
Practice builds that exercise this skill by re-creating a real technology.
- Build your own Template EngineIntro · 4–8 h
- Build your own JSON ParserIntro · 3–6 h
- Build your own Regex EngineIntermediate · 6–12 h
- Build your own Programming LanguageIntermediate · 20–40 h
- Build your own CompilerAdvanced · 30–60 h
References
Hard prerequisites
Unlocks
On these roadmaps
Progress and evidence for this skill are shared across all of them.