Recursion II: Backtracking & Divide and Conquer
Two powerful uses of recursion: exploring every choice while undoing mistakes (backtracking), and splitting a problem into independent halves (divide and conquer).
After this lesson you will be able to
- Write the backtracking template: choose, explore, un-choose, with a clear base case.
- Generate subsets, combinations and permutations, and handle duplicates and reuse correctly.
- Prune the search tree so hopeless branches are abandoned early, and see how much that saves.
- Solve a constraint puzzle (N-Queens) by backtracking.
- Apply divide and conquer: split, solve each part independently, combine.
Before you start. Recursion I (base case, call stack, the leap of faith). Trees help for picturing the search as a tree of choices.