Backtracking vs Brute Force
Brute force tries every full answer. Backtracking builds an answer step by step and gives up on a path as soon as it cannot work, so it skips most of the tries.
Backtracking
Try a choice, and step back to try another when it leads to a dead end.
Backtracking builds an answer one choice at a time. After each choice, it checks whether the answer can still work. If it cannot, it undoes the last choice and tries the next one. This skips whole groups of choices that are sure to fail. Sudoku solvers, maze solvers and puzzles like eight queens use it.
Brute Force
You try each possible answer in turn. You stop when one works.
Brute force solves a problem by trying every possible answer until one works. It is simple to write and always finds the answer, if there is one. The trouble is the number of tries, which can grow huge very fast. A 4-digit code has 10,000 options, but a 12-letter password has far more than anyone could try. It is often the first version, before a smarter one replaces it.
In one line
- Backtracking
- Try a choice, and step back to try another when it leads to a dead end.
- Brute Force
- You try each possible answer in turn. You stop when one works.