Begin Algo
Algorithms · 5 lessons

Recursion & BacktrackingTry everything, but turn back early

Backtracking is disciplined brute force: make a choice, recurse, undo the choice on the way back. It is DFS over a decision tree, and it is what solves sudoku, permutations and N-queens. Pruning is what decides whether it finishes this century.

Why learn Recursion & Backtracking

Where it shows up
Timetabling and seating

Give each class a slot; on a clash try the next one; if nothing fits, go back and change the previous class. That is backtracking, and N-queens is its textbook form.

→ Lesson: N-Queens
Enumerating combinations

Listing every subset, permutation or combination — testing every combination of feature flags, generating every variant of a password.

→ Lesson: Subsets
Sudoku and crosswords

Put a digit in a cell, back out when it breaks a rule. The way a person solves it and the way a program solves it have the same shape.

→ Lesson: Word Search

Lessons

5 lessons