- Technique used to solve problems with a large search space, by systematically trying and eliminating possibilities.
- Hence applied to problems not solvable in polynomial time and which are generally solvable using exhaustive search.
We use backtracking for NP Complete problem (Hard problem). As hard problem requires exponential time to solve it systematically.
- Each step tries to extend a partial solution by adding another element at the end.
- Tests if a solution is obtained. If yes, output, count and continue
- Otherwise checks, if it is extendible. If yes, continue.
- Otherwise backtracks.
- Construct the state space tree
- Explore the state space tree using depth first search.
- Prune non promising nodes.
State space tree
- A tree of choices being made.
- Root represents an initial state.
- Nodes of the first level represent the choices made for the first component of the solution.
- Nodes of the second level represent the choices for the second component.
- Thus each node represents a partial solution.
- An edge from node x to y exists if y was created by advancing from x.
- Node is promising if it corresponds to a partially constructed solution that may still lead to a complete solution.
- Otherwise it is called non-promising.
- Leaves represent either non-promising dead ends or complete solution found.
- Finding a hamiltonian circuit
- Finding the most valuable subset of items in a knapsack
- Going through a maze
- Solving the 8-Queens problem