Backtracking is a problem-solving method used for constraint satisfaction problems, allowing for incremental solution building by making a sequence of decisions. It is a recursive approach that eliminates candidates that do not meet constraints, making it generally faster than brute force methods. The algorithm systematically explores the solution space using depth-first search and backtracks when a partial solution fails to satisfy the constraints.
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 ratings0% found this document useful (0 votes)
3 views2 pages
Backtracking
Backtracking is a problem-solving method used for constraint satisfaction problems, allowing for incremental solution building by making a sequence of decisions. It is a recursive approach that eliminates candidates that do not meet constraints, making it generally faster than brute force methods. The algorithm systematically explores the solution space using depth-first search and backtracks when a partial solution fails to satisfy the constraints.
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
You are on page 1/ 2
What is Backtracking?
Backtracking is an intelligent way of gradually building the solution. Typically, it is
applied to constraint satisfaction problems like Sudoku, crossword, 8-queen puzzles, chess, and many other games. Dynamic programming and greedy algorithms are optimization techniques, whereas backtracking is s general problem-solving method. It does not guarantee an optimal solution. ▪ A solution to many problems can be viewed as the making of a sequence of decisions. For example, TSP can be solved by making the sequence of the decision of which city should be visited next. ▪ Similarly, a knapsack is also viewed as a sequence of decisions. At each step, the decision to select or reject the given item is made. ▪ Backtracking builds the solution incrementally. Partial solutions that do not satisfy the constraints are abandoned. ▪ Backtracking is a recursive approach, and it is a refinement of the brute force method. The brute force approach evaluates all possible candidates, whereas backtracking limits the search by eliminating the candidates that do not satisfy certain constraints. Hence, backtracking algorithms are often faster than brute force approaches. ▪ Backtracking algorithms are used when we have a set of choices, and we don’t know which choice will lead to the correct solution. The algorithm generates all partial candidates that may generate a complete solution. ▪ The solution in backtracking is expressed as an n-tuple (x1, x2,… xn), where xi is chosen from the finite set of choices, Si. Elements in the solution tuple are chosen such that they maximize or minimize the given criterion function C(x1, x2,…, xn). ▪ Let C be the set of constraints on problem P, and let D is the set of all the solutions that satisfy the constraints C. Then ▪ Finding if a given solution is feasible or not is the decision problem. ▪ Finding the best solution is the optimization problem. ▪ Listing all feasible solutions is an enumeration problem. ▪ Backtracking systematically searches the set of all feasible solutions, called solution space, to solve the given problem. ▪ Each choice leads to a new set of partial solutions. Partial solutions are explored in DFS (Depth First Search) order. ▪ If a partial solution satisfies a certain bounding function, then the partial solution is explored in depth-first order. ▪ If the partial solution does not satisfy the constraint, it will not be explored further. The algorithm backtracks from that point and explores the next possible candidate. ▪ Such processing is convenient to represent using a state space tree. In a state space tree, the root represents the initial state before the search begins.