Back T
Back T
Backtracking
General Concepts
Algorithm strategy
Approach to solving a problem
May combine several approaches
Algorithm structure
Iterative execute action in loop
Recursive reapply action to sub problem(s)
Problem type
Satisfying find any satisfactory solution
Optimization find best solutions (vs. cost
metric)
Suppose you have to make a series of
decisions, among various choices, where
You don’t have enough information to know
what to choose
Each decision leads to a new set of choices
Some sequence of choices (possibly more than
one) may be a solution to your problem
Backtracking is a methodical way of trying
out various sequences of decisions, until you
find one that “works”
Solving a maze
• Given a maze, find a path from start to finish
• At each intersection, you have to decide between three
or fewer choices:
– Go straight
– Go left
– Go right
• You don’t have enough information to choose correctly
• Each choice leads to another set of choices
• One or more sequences of choices may (or may not)
lead to a solution
• Many types of maze problem can be solved with
backtracking
• Backtracking is a technique used to solve
problems with a large search space, by
systematically trying and eliminating
possibilities.
• A standard example of backtracking would be
going through a maze.
– At some point in a maze, you might have two
options of whichPortion
direction
A
to go:
on
ncti
Ju
Portion B
Backtracking
One strategy would be to try on
ncti
going through Portion A of Ju
the maze.
Portion B
If you get stuck before you
find your way out, then
Portion A
you "backtrack" to the
junction.