Backtracking - Introduction
Backtracking - Introduction
By
Dr.V.Venkateswara Rao
Backtracking -Introduction
Backtracking is an algorithmic-technique for solving problems recursively by
trying to build a solution incrementally, one piece at a time
( One input at a time),
removing those solutions that fail to satisfy the constraints of the problem
at any point of time.
Backtracking can be applied only for problems that admit the concept of a “partial
candidate solution” and a relatively quick test of whether it can be completed to a valid
solution.
Backtracking is often much faster than brute force enumeration of all candidates since it
can eliminate a large number of candidates with a single test.
Backtracking - How it works?
In any backtracking problems, the algorithm tries to find a path to the feasible
solution which has some intermediary checkpoints. In case they don’t lead to the
feasible solution, the problem can backtrack from the checkpoints and take another
path in search of the solution.
Here S is the starting point of the problem. We start from S, we go to find solution S1 via
the intermediate point I1. But we find that the solution S1 is not a feasible solution to
our problem.
Hence, we backtrack (go back) from S1, go back to I1, go back to S and then check for the
feasible solution S2. This process happens till we arrive at a feasible solution.
Here, S1 and S2 are not the feasible solutions.
Only S3 is a feasible solution as per our example.
When we look at this example, we can see that we traverse through all possible
combinations, till we arrive at the feasible solution.