0% found this document useful (0 votes)
4 views2 pages

Backtracking Algorithm

A backtracking algorithm is a brute force problem-solving method that explores all possible solutions and backtracks if a current solution is unsuitable. It is particularly useful for problems with multiple solutions, such as arranging objects under certain constraints. Applications of backtracking include finding Hamiltonian paths, solving the N Queen problem, maze solving, and the Knight's tour problem.

Uploaded by

Prasanth T K
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Backtracking Algorithm

A backtracking algorithm is a brute force problem-solving method that explores all possible solutions and backtracks if a current solution is unsuitable. It is particularly useful for problems with multiple solutions, such as arranging objects under certain constraints. Applications of backtracking include finding Hamiltonian paths, solving the N Queen problem, maze solving, and the Knight's tour problem.

Uploaded by

Prasanth T K
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Backtracking Algorithm

A backtracking algorithm is a problem-solving algorithm that uses a brute


force approach for finding the desired output.

The Brute force approach tries out all the possible solutions and chooses
the desired/best solutions.

The term backtracking suggests that if the current solution is not suitable,
then backtrack and try other solutions. Thus, recursion is used in this
approach.

This approach is used to solve problems that have multiple solutions. If you
want an optimal solution, you must go for dynamic programming.
State Space Tree

A space state tree is a tree representing all the possible states (solution or
nonsolution) of the problem from the root as an initial state to the leaf as a
terminal state.

State Space Tree

Example Backtracking Approach


Problem: You want to find all the possible ways of arranging 2 boys and 1
girl on 3 benches. Constraint: Girl should not be on the middle bench.
Solution: There are a total of 3! = 6 possibilities. We will try all the
possibilities and get the possible solutions. We recursively try all the
possibilities.

All the possibilities are:

All the possibilities


The following state space tree shows the possible solutions.

State tree with all the solutions

Backtracking Algorithm Applications

1. To find all Hamiltonian Paths present in a graph.


2. To solve the N Queen problem.
3. Maze solving problem.
4. The Knight's tour problem.

You might also like