## Branch and bound vs backtrackingBefore understanding the branch and bound and backtracking differences, we should know about the branch and bound and backtracking separately.
Backtracking is nothing but the modified process of the Consider the box, and we have three objects of three different colors. One object is of red color, the second object is of green color, and the third object is of blue color. Now, we have to keep these objects inside the box, and we have multiple options. As per the Brute force approach, we have to consider all the options and identify the best option among all the possible options.
Suppose we first fill red object, after then green object and then blue object. This is the first solution to this problem. The possible solution is red, green, and blue. The second solution is to keep the red object, then the blue object, and then the green object. The possible solution red, blue, and green. The third solution can be to keep the green object, then the red object and then the blue object. The possible solution is green, red and blue. The fourth solution is to keep the green object, then the blue object and then the red object. The possible solution is green, blue and red. The fifth solution is to keep the blue object, then green object and then red object. The possible solution is blue, green and red. The sixth solution is to keep the blue object, then the red object and then the green object. The possible solution is blue, red and green. The above are the possible solutions, and we have to identify the best possible solution out of all the possible solutions. This approach is known as a brute force approach. Backtracking is similar to the brute force approach, but it is a modified process of the brute force approach.
The above is the figure that shows the possible solutions to the above problem. Now we will see that how these solutions are represented in backtracking. In backtracking, solutions are represented in the form of a tree and that tree is known as a state space tree. Since backtracking follows the DFS, the tree will be formed using DFS, which is known as a
Consider the first solution, i.e., Consider the second solution, i.e., The next solution is The next solution is The next solution is The next solution is The above is the state space tree that shows all the possible solutions related to the problem. Therefore, we can say that the state space tree can be used to represent all the solutions in backtracking. Using backtracking, we can solve the problem that has some constraints and we can find the solution based on these constraints. Suppose in the above example; the constraint is blue color object must not be in the middle (bounding function). The first solution is The second solution is The next solution is The next solution is The above is the state space tree that does not have blue object in the middle of the solution.
It is similar to backtracking. The concept branch and bound and backtracking follow the Brute force method and generate the state space tree. But both of them follows different approaches. The way to generate the tree is different. Backtracking follows the DFS, whereas the branch n bound follows the BFS to generate the tree. Now we will understand the branch n bound through an example. As it follows the BFS, so first all the nodes of the same level are added then we move to the next level.
First, we take the root node. Now we have three possibilities that either we select red, green, or blue objects as shown below. In this case, we have completed the first level. Now we move to the next level. In the case of red object, we have two possibilities that either we select green or blue object shown as below: In the case of green object, we have two possibilities that either we select red or blue object shown as below: In the case of blue object, we have two possibilities that either we select red or green object shown as below: We move to the third level. In the case of a green object, only one object, i.e., blue, can be added. In the case of a blue object, only one object, i.e., green, can be added. In the case of a red object, only one object, i.e., blue, can be added. In the case of a blue object, only one object, i.e., red, can be added. In the case of a green object, only one object, i.e., red, can be added. In the case of a red object, only one object, i.e., green, can be added.
The problems that can be solved by using backtracking are: - 8 Queens problem
- Knapsack problem using backtracking
The problem that can be solved by using branch and bound is: - Travelling Salesman Problem
## Differences between Branch n bound and Backtracking
Next TopicBranch and bound |