Algorithms

Backtracking

A way to find every solution by trying options one at a time: you move forward with a choice and, if it leads nowhere, undo it and try another.

Example

To open a 3-digit lock without the code, you try 0-0-0, 0-0-1... and each time it fails you change the last digit: up to 1,000 tries.

Test yourself: Backtracking

Backtracking

Backtracking is an ___ search: it tries every possible option.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.