Codele / Algorithms
Backtracking
Some puzzles have no formula. You try a choice, keep going, and when you hit a dead end you undo the last choice and try the next one.
- Backtracking means: try a choice, go on, and if you reach a dead end, undo the last choice and try the next one.
- A dead end is a spot where no choice works any more. Reaching one is normal, not a mistake.
- Undoing only the last choice keeps all the earlier good choices. Nothing starts from scratch.
- The code is often recursive: each call handles one row, and returning false means “undo and try another”.
- Backtracking checks choices in order, so it finds a solution if one exists.
Loading the playable lesson…