0% found this document useful (0 votes)
8 views72 pages

Unit 4

Uploaded by

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

Unit 4

Uploaded by

star light
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

Dynamic Programming, Backtracking

and Branch and Bound

Unit: 4

Design & Analysis of Algorithms

B.Tech 5th Sem

1
11/20/2024
Dynamic Programming(CO4)

• In the divide-and-conquer strategy, you divide the problem to


be solved into subproblems.
• The subproblems are further divided into smaller subproblems.
• That task will continue until you get subproblems that can be
solved easily.
• The basic idea of dynamic programming is to use a table to
store the solutions of solved subproblems.
• If you face a subproblem again, you just need to take the
solution in the table without having to solve it again.
• Therefore, the algorithms designed by dynamic programming
are very effective.

11/20/2024 2
Dynamic Programming

To solve a problem by dynamic programming, you need to do the


following tasks:
 Find solutions of the smallest subproblems.
 Find out the formula (or rule) to build a solution of subproblem
through solutions of even smallest subproblems.
 Create a table that stores the solutions of subproblems. Then
calculate the solution of subproblem according to the found
formula and save to the table.
 From the solved subproblems, you find the solution of the
original problem.

11/20/2024 3
Dynamic Programming(CO4)

Knapsack problem(0/1)

• Consider a thief gets into a home to rob and he carries a knapsack.


There are fixed number of items in the home — each with its own
weight and value — Jewelry, with less weight and highest value vs
tables, with less value but a lot heavy.

• To add fuel to the fire, the thief has an old knapsack which has
limited capacity.

• Obviously, he can’t split the table into half or jewelry into 3/4ths. He
either takes it or leaves it.

11/20/2024 4
Dynamic Programming(CO4)

Dynamic-Programming Approach
• Let i be the highest-numbered item in an optimal
solution S for W dollars. Then S' = S - {i} is an optimal solution
for W - wi dollars and the value to the solution S is Vi plus the value
of the sub-problem.
• We can express this fact in the following formula: define c[i, w] to
be the solution for items 1,2, … , i and the maximum weight w.
• The algorithm takes the following inputs
• The maximum weight W
• The number of items n
• The two sequences v = <v1, v2, …, vn> and w = <w1, w2, …, wn>

11/20/2024
5
Dynamic Programming(CO4)

Dynamic-0-1-knapsack (v, w, n, W)

• for w = 0 to W do
• c[0, w] = 0
• for i = 1 to n do
• c[i, 0] = 0
• for w = 1 to W do
• if wi ≤ w then
• if vi + c[i-1, w-wi] then
• c[i, w] = vi + c[i-1, w-wi]
• else c[i, w] = c[i-1, w]
• else
• c[i, w] = c[i-1, w]

11/20/2024 6
Dynamic Programming(CO4)

• Knapsack problem(0/1)

• The set of items to take can be deduced from the table, starting
at c[n, w] and tracing backwards where the optimal values came
from.
• If c[i, w] = c[i-1, w], then item i is not part of the solution, and we
continue tracing with c[i-1, w]. Otherwise, item i is part of the
solution, and we continue tracing with c[i-1, w-W].

Analysis

• This algorithm takes θ(n, w) times as table c has (n + 1).(w + 1)


entries, where each entry requires θ(1) time to compute.

11/20/2024 7
Dynamic Programming(CO4)
Knapsack problem(0/1)

Steps
• To calculate the maximum value that we can obtain with item i, we
first need to compare the weight of item i with the knapsack’s weight
capacity.

• Obviously, if item i weighs more than what the knapsack can hold, we
can’t include it, so it does not make sense to perform the calculation.

• In that case, the solution to this problem is simply the maximum value
that we can obtain without item i (i.e. the value in the row above, at
the same column).

11/20/2024 8
Dynamic Programming(CO4)

Knapsack problem(0/1)
• However, suppose that item i weighs less than the knapsack’s
capacity.
• We thus have the option to include it, if it potentially increases the
maximum obtainable value.
• The maximum obtainable value by including item i is thus = the
value of item i itself + the maximum value that can be obtained with
the remaining capacity of the knapsack.
• We obviously want to make full use of the capacity of our knapsack,
and not let any remaining capacity go to waste.
• Therefore, at row i and column j (which represents the maximum
value we can obtain there), we would pick either the maximum
value that we can obtain without item i, or the maximum value that
we can obtain with item i, whichever is larger.
11/20/2024 9
Dynamic Programming(CO4)
• For Example

• At row 3 (item 2), and column 5 (knapsack capacity of 4), we can


choose to either include item 2 (which weighs 4 units) or not.

• If we choose not to include it, the maximum value we can obtain is


the same as if we only have item 1 to choose from (which is found
in the row above, i.e. 0).

11/20/2024 10
Dynamic Programming(CO4)

Knapsack problem(0/1)

• If we want to include item 2, the maximum value we can obtain with


item 2 is the value of item 2 (40) + the maximum value we can
obtain with the remaining capacity (which is 0, because the
knapsack is completely full already).

• At row 3 (item 2), and column 10 (knapsack capacity of 9), again,


we can choose to either include item 2 or not.

• If we choose not to, the maximum value we can obtain is the same
as that in the row above at the same column, i.e. 10 (by including
only item 1, which has a value of 10).

11/20/2024 11
Dynamic Programming(CO4)

• Knapsack problem(0/1)

• If we include item 2, we have a remaining knapsack capacity of 9 -


4 = 5.

• We can find out the maximum value that can be obtained with a
capacity of 5 by looking at the row above, at column 5.

• Thus, the maximum value we can obtain by including item 2 is 40


(the value of item 2) + 10 = 50.

11/20/2024 12
Dynamic Programming(CO4)

Knapsack problem(0/1)

• We pick the larger of 50 vs 10, and so the maximum value we can


obtain with items 1 and 2, with a knapsack capacity of 9, is 50.

• Once the table has been populated, the final solution can be found at
the last row in the last column, which represents the maximum value
obtainable with all the items and the full capacity of the knapsack.

• For more examples watch the following youtube link


• https://www.youtube.com/watch?v=oTTzNMHM05I

11/20/2024 13
Dynamic Programming(CO4)

All Pair Shortest Path

• The all pair shortest path algorithm is also known as Floyd-Warshall


algorithm is used to find all pair shortest path problem from a given
weighted graph.

• As a result of this algorithm, it will generate a matrix, which will represent


the minimum distance from any node to all other nodes in the graph.

• At first the output matrix is same as given cost matrix of the graph. After
that the output matrix will be updated with all vertices k as the intermediate
vertex.

• The time complexity of this algorithm is O(V3), here V is the number of


vertices in the graph.
11/20/2024 14
Dynamic Programming(CO4)
All Pair Shortest Path
• Representation

11/20/2024 15
Dynamic Programming(CO4)

All Pair Shortest Path

11/20/2024 16
Dynamic Programming(CO4)
All Pair Shortest Path
Example: Input-The cost matrix of the graph.
0 3 6

3 0 2 1

6 2 0 1 4 2

1 1 0 2 4

4 0 2 1

2 2 0 1

4 1 1 0

11/20/2024 17
Dynamic Programming(CO4)

• All Pair Shortest Path


• Output-Matrix of all pair shortest paths
0 3 4
3 0 2 1
4 2 0 1 3 3

1 1 0 2 3

3 0 2 1

2 2 0 1
3 1 1 0

For more examples refer this link


https://www.youtube.com/watch?v=oNI0rf2P9gE

11/20/2024 18
Dynamic Programming(CO4)

Resource Allocation problem

• A resource allocation problem in which ‘m’ resources are to be


allocated to ‘n’ projects. If ‘j’ resources are allocated to project I then
profit is P(i,j).

• The problem is to allocate the resource to the ‘n’ projects in such a


way as to maximize total next profit.

• This problem can be formulated as an n+1 stage graph problem as


follows . Stage i, 0 i ≤ n-1, represents project I, there are m+1
vertices, associated with stage i, 1 i ≤ n-1, stage 0 and n each one
vertex S and T respectively. Vertex (i,j) represents I, resources
allocated to projects 1,2,……..j.
11/20/2024 19
Dynamic Programming(CO4)

Resource Allocation problem

• An optimal allocation of resources is defined by a maximum cost of a


path from S to T.

• A dynamic programming formulation for a k-stage is obtained by first


noticing that every S to T path is result of a sequence k-2 decisions.
• Let c(S,k) be a cost of path from node S to k and d( k, T) be the cost
of path from node k to T, via. some intermediate node , which can be
calculated recursively.

d(S,T)= max{c(S,k) +d(k,T)}

11/20/2024 20
Dynamic Programming(CO4)
• Consider the following example to understand the concept of
multistage graph.

https://www.tutorialspoint.com/design_and_analysis_of_algorithms/d
esign_and_analysis_of_algorithms_multistage_graph.htm

11/20/2024 21
Dynamic Programming(CO4)

• According to the formula, we have to calculate the cost (i, j) using


the following steps

• Step-1: Cost (K-2, j)

• In this step, three nodes (node 4, 5. 6) are selected as j. Hence, we


have three options to choose the minimum cost at this step.

Cost(3, 4) = min {c(4, 7) + Cost(7, 9),c(4, 8) + Cost(8, 9)} = 7


Cost(3, 5) = min {c(5, 7) + Cost(7, 9),c(5, 8) + Cost(8, 9)} = 5
Cost(3, 6) = min {c(6, 7) + Cost(7, 9),c(6, 8) + Cost(8, 9)} = 5

11/20/2024 22
Dynamic Programming(CO4)

• Step-2: Cost (K-3, j)


• Two nodes are selected as j because at stage k - 3 = 2 there are two
nodes, 2 and 3. So, the value i = 2 and j = 2 and 3.

Cost(2, 2) = min {c(2, 4) + Cost(4, 8) + Cost(8, 9),c(2, 6) +


Cost(6, 8) + Cost(8, 9)}
=8
Cost(2, 3) = {c(3, 4) + Cost(4, 8) + Cost(8, 9), c(3, 5) + Cost(5, 8)+
Cost(8, 9), c(3, 6) + Cost(6, 8) + Cost(8, 9)}
= 10

11/20/2024 23
Dynamic Programming(CO4)

• Step-3: Cost (K-4, j)


Cost (1, 1) = {c(1, 2) + Cost(2, 6) + Cost(6, 8) + Cost(8, 9), c(1, 3)
+
Cost(3, 5) + Cost(5, 8) + Cost(8, 9))}
= 12
c(1, 3) + Cost(3, 6) + Cost(6, 8 + Cost(8, 9))} = 13
Hence, the path having the minimum cost is 1→ 3→ 5→ 8→ 9.

For more examples refer the video


https://www.youtube.com/watch?v=9iE9Mj4m8jk

11/20/2024 24
Backtracking(CO4)- Objective

This objective of this topic is to make students understand


about
• Concepts of Backtracking
• Graph Colouring
• N-Queens
• Sum of Subsets
• Hamiltonian Cycle

11/20/2024 25
Prerequisite and Recap

• Prerequisite
• Algorithms Concepts
• C programming
• Graph

• Recap
• Dynamic Programming

11/20/2024 26
Backtracking (CO4)

• Backtracking is an algorithmic-technique for solving problems


recursively by trying to build a solution incrementally, one piece
at a time, removing those solutions that fail to satisfy the
constraints of the problem at any point of time.

• It is a technique based on algorithm to solve problem. It uses


recursive calling to find the solution by building a solution step by
step increasing values with time.

• It removes the solutions that doesn't give rise to the solution of the
problem based on the constraints given to solve the problem.

11/20/2024 27
Backtracking

• Backtracking algorithm is applied to some specific types of


problems.
• Decision problem used to find a feasible solution of the
problem.
• Optimisation problem used to find the best solution that can
be applied.
• Enumeration problem used to find the set of all feasible
solutions of the problem

• In backtracking problem, the algorithm tries to find a sequence


path to the solution which has some small checkpoints from
where the problem can backtrack if no feasible solution is found
for the problem.

11/20/2024 28
Backtracking

For Example,

• Here, Green is the start point, blue is the intermediate point, red are
points with no feasible solution, dark green is end solution.

• when the algorithm propagates to an end to check if it is a solution


or not, if it is then returns the solution otherwise backtracks to the
point one step behind it to find track to the next point to find
solution.

11/20/2024 29
Backtracking

ALGORITHM
Step 1 − if current_position is goal, return success

Step 2 − else,

Step 3− if current_position is an end point, return failed.

Step 4− else, if current_position is not end point, explore


and repeat above steps.

11/20/2024 30
Backtracking

Graph Colouring Problem


• Given an undirected graph and a number m, determine if the
graph can be coloured with at most m colours such that no two
adjacent vertices of the graph are colored with the same color.

• Here coloring of a graph means the assignment of colors to all


vertices.

11/20/2024 31
Backtracking

Graph Colouring Problem


Input:
• A 2D array graph[V][V] where V is the number of vertices
in graph and graph[V][V] is adjacency matrix
representation of the graph.
• A value graph[i][j] is 1 if there is a direct edge from i to j,
otherwise graph[i][j] is 0.
• An integer m which is the maximum number of colors that
can be used

Output:
An array color[V] that should have numbers from 1 to m.
color[i] should represent the color assigned to the ith vertex.

11/20/2024 32
Backtracking

N- Queens Problem

• N - Queens problem is to place n - queens in such a manner on an


n x n chessboard that no queens attack each other by being in the
same row, column or diagonal.

• It can be seen that for n =1, the problem has a trivial solution, and
no solution exists for n =2 and n =3.

• So first we will consider the 4 queens problem and then generate


it to n - queens problem.

• Given a 4 x 4 chessboard and number the rows and column of the


chessboard 1 through 4.

11/20/2024 33
Backtracking

N- Queens Problem

Since, we have to place 4 queens such as q1 q2 q3 and q4 on the


chessboard, such that no two queens attack each other. In such a
conditional each queen must be placed on a different row, i.e.,
we put queen "i" on row "i."

11/20/2024 34
Backtracking

N- Queens Problem

• Now, we place queen q1 in the very first acceptable position (1, 1).

• Next, we put queen q2 so that both these queens do not attack each
other.

• We find that if we place q2 in column 1 and 2, then the dead end is


encountered.

• Thus the first acceptable position for q 2 in column 3, i.e. (2, 3) but
then no position is left for placing queen 'q 3' safely.

11/20/2024 35
Backtracking

N- Queens Problem

• So we backtrack one step and place the queen 'q 2' in (2, 4), the
next best possible solution. Then we obtain the position for
placing 'q3' which is (3, 2).

• But later this position also leads to a dead end, and no place is
found where 'q4' can be placed safely.

• Then we have to backtrack till 'q1' and place it to (1, 2) and then
all other queens are placed safely by moving q2 to (2, 4), q3 to (3,
1) and q4 to (4, 3).

11/20/2024 36
Backtracking

N- Queens Problem

• That is, we get the solution (2, 4, 1, 3).

• This is one possible solution for the 4-queens problem.

• For another possible solution, the whole method is repeated for


all partial solutions. The other solutions for 4 - queens problems
is (3, 1, 4, 2) i.e.

11/20/2024 37
Backtracking

N- Queens Problem

• Fig shows the complete state space for 4 - queens problem. But
we can use backtracking method to generate the necessary node
and stop if the next node violates the rule, i.e., if two queens are
attacking.

• It can be seen that all the solutions to the 4 queens problem can
be represented as 4 - tuples (x1, x2, x3, x4) where xi represents the
column on which queen "qi" is placed.

11/20/2024 38
Backtracking

4- Queens Problem

11/20/2024 39
Backtracking

N- Queens Problem

Place (k, i)
{
For j ← 1 to k - 1
do if (x [j] = i)
or (Abs x [j]) - i) = (Abs (j - k))
then return false;
return true;
}
• Place (k, i) return true if a queen can be placed in the kth row
and ith column otherwise return is false.
• x [] is a global array whose final k - 1 values have been set. Abs
(r) returns the absolute value of r.

11/20/2024 40
Backtracking

N- Queens Problem
• x [] is a global array whose final k - 1 values have been set.
Abs (r) returns the absolute value of r.

N - Queens (k, n)
{
For i ← 1 to n
do if Place (k, i) then
{
x [k] ← i;
if (k ==n) then
write (x [1....n));
else
N - Queens (k + 1, n);
}
}
11/20/2024 41
Backtracking

8- Queens Problem

1.Thus, the solution for 8 -


queen problem for (4, 6, 8, 2, 7, 1, 3, 5).
2.If two queens are placed at position (i, j) and (k, l).
3.Then they are on same diagonal only if (i - j) = k - l or i
+ j = k + l.
4.The first equation implies that j - l = i - k.
5.The second equation implies that j - l = k - i.
6.Therefore, two queens lie on the duplicate diagonal if an
d only if |j-l|=|i-k|
11/20/2024 42
Backtracking

Hamiltonian Cycles
• Hamiltonian Path in an undirected graph is a path that visits each
vertex exactly once.
• A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian
Path such that there is an edge (in the graph) from the last vertex
to the first vertex of the Hamiltonian Path.

11/20/2024 43
Backtracking

Sum of Subsets Problem


• Subset sum problem is to find subset of elements that are
selected from a given set whose sum adds up to a given
number K.

• We are considering the set contains non-negative values. It is


assumed that the input set is unique (no duplicates are
presented).

• Here backtracking approach is used for trying to select a valid


subset when an item is not valid, we will backtrack to get the
previous subset and add another element to get the solution.

11/20/2024 44
Backtracking

Sum of Subsets Problem


• Subset sum problem is to find subset of elements that are
selected from a given set whose sum adds up to a given
number K.

• We are considering the set contains non-negative values. It is


assumed that the input set is unique (no duplicates are
presented).

• Here backtracking approach is used for trying to select a valid


subset when an item is not valid, we will backtrack to get the
previous subset and add another element to get the solution.

11/20/2024 45
Backtracking

Sum of Subsets Problem


Backtracking
. Algorithm for Subset Sum
Using exhaustive search we consider all subsets irrespective of
whether they satisfy given constraints or not. Backtracking can be
used to make a systematic consideration of the elements to be selected.

Algorithm
subsetSum(set, subset, n, subSize, total, node, sum)
Input: The given set and subset, size of set and subset, a total of the
subset, number of elements in the subset and the given sum.
Output: All possible subsets whose sum is the same as the given sum.

11/20/2024 46
Backtracking

Sum of Subsets Algorithm

11/20/2024 47
Backtracking

Sum of Subsets Example


Given a set S = (3, 4, 5, 6) and X =9. Obtain the subset sum using
Backtracking approach.
Solution:
Initially S = (3, 4, 5, 6) and X =9.
S'= (∅)

• The implicit binary tree for the subset sum problem is shown in Fig.

• The number inside a node is the sum of the partial solution elements
at a particular level.

• Thus, if our partial solution elements sum is equal to the positive


integer 'X' then at that time search will terminate, or it continues if all
the possible solution needs to be obtained.

11/20/2024 48
Backtracking

Sum of Subsets Example

11/20/2024 49
Backtracking

Sum of Subsets Example

Input: The Set: {10, 7, 5, 18, 12, 20, 15}


The sum Value: 35
Output:
All possible subsets of the given set, where sum of each element for
every subsets is same as the given sum value.
{10, 7, 18}
{10, 5, 20}
{5, 18, 12}
{20, 15}

11/20/2024 50
Branch and Bound(CO4)- Objective

This objective of this topic is to make students understand


about
• Concepts of Branch and Bound
• Travelling Salesman Problem

11/20/2024 51
Prerequisite and Recap

• Prerequisite
• Algorithms Concepts
• C programming
• Graph

• Recap
• Backtracking

11/20/2024 52
Branch and Bound (CO4)

• Branch and bound is an algorithm design paradigm which is


generally used for solving combinatorial optimization problems.

• These problems are typically exponential in terms of time


complexity and may require exploring all possible permutations in
worst case.

• The Branch and Bound Algorithm technique solves these problems


relatively quickly.

11/20/2024 53
Branch and Bound

Travelling Salesman Problem


Given a set of cities and distance between every pair of cities, the
problem is to find the shortest possible tour that visits every city
exactly once and returns to the starting point.

• In Branch and Bound method, for current node in tree, we compute


a bound on best possible solution that we can get if we down this
node.

• If the bound on best possible solution itself is worse than current


best (best computed so far), then we ignore the subtree rooted with
the node.

11/20/2024 54
Branch and Bound

Travelling Salesman Problem

Note that the cost through a node includes two costs.

1) Cost of reaching the node from the root (When we reach a node, we
have this cost computed)

2) Cost of reaching an answer from current node to a leaf (We compute


a bound on this cost to decide whether to ignore subtree with this node
or not).

11/20/2024 55
Branch and Bound

Travelling Salesman Problem- Example

• In this method we expand the node which is most promising means the
node which promises that expanding or choosing it will give us the
optimal solution.

• So we prepare the tree starting from root then we expand it.

• The cost matrix is defined by


C(i,j) = W(i,j) , if there is a direct path from Ci to Cj.
=, If there is no direct path from Ci to Cj.

11/20/2024 56
Branch and Bound

Travelling Salesman Problem- Example


Consider the following cost matrix

Here C(0,2)=30, C(4,0)=16, C(1,1)= and so on. Below is the


state space tree for the TSP , which shows optimal solution
marked in green
(https://www.techiedelight.com/travelling-salesman-problem-using-branch-and-
bound/
)

11/20/2024 57
Branch and Bound

11/20/2024 58
Branch and Bound

Travelling
. Salesman Problem- Steps

• As we can see from above diagram , every node has a cost associated
to it.

• When we go from city I to city j, cost of a node j will be sum of cost of


parent node I, cost of the edge (I,j) and lower bound of the path starting
at node j.

• As root node is the first node to be expanded , it doesn’t have any


parent. So cost will be only lower bound of the path starting at root.

• To get the lower bound of the path starting from the node , we reduce
each row and column in such a wat that there must be atleast one zero
in each row and column.
11/20/2024 59
Branch and Bound

• . For doing this, we need to reduce the minimum value from each
element in each row and column.

Let’s start from root node


• We reduce the minimum value in each row from each element in that
row.
• Minimum in each row of cost matrix M is marked by blue[10,2,2,3,4]
below.

11/20/2024 60
Branch and Bound

• . After reducing the row, we get the below matrix. We then reduce
the minimum value in each column from each element in that
column.

• Minimum in each column is marked by blue[1 0 3 0 0]. After


reducing the column, we get below reduced matrix. This matrix
will be further processed by child nodes of root node to calculate
their lower bound.

11/20/2024 61
Branch and Bound

• The total expected cost at the root node is sum of all reductions.
• Cost=[10 2 2 3 4] + [1 0 3 0 0]= 25
• Since we have discovered the root node C0, the next node to be
expanded can be any node from C1,C2, C3, C4. Whichever node
has minimum cost, that node will be expanded further. So we have
to find out the expanding cost of each node.

11/20/2024 62
Branch and Bound
• The parent node (C0) has below reduced matrix-
.

• Let us consider edge from 0 1

1. As we are adding edge (0,1) to our search space, we get outgoing


edges for city 0 to infinity and all incoming edges to city 1 to
infinity. We also set (1,0) to infinity.

2. So in reduced matrix of parent node we change all the elements in


row 0 and column 1 and at index (1,0) to infinity(marked in red).

11/20/2024 63
Branch and Bound

The resulting cost matrix is

11/20/2024 64
Branch and Bound

.
3. We try to calculate lower bound of the path starting at node 1 using
above resulting cost matrix.

4. The lower bound is 0 as matrix is already in reduced form. i.e. all


rows and all columns have zero value.

Therefore for node 1, cost will be

Cost= cost of node 0 + cost of the edge (0,1) + lower bound of the
path starting at node 1
= 25 + 10 +0= 35

11/20/2024 65
Branch and Bound

.Lets consider edge from 0 2

1. Change all the elements in row 0 and column 2 and at index(2,0) to


infinity(marked in red).

The resulting cost matrix is:

11/20/2024 66
Branch and Bound

• Now calculate lower bound of the path starting at node 2 using the
Approach discussed earlier. Resulting matrix will be-

Therefore the cost of node 2, cost will be

Cost = Cost of node 0 + cost of the edge (0,2) + Lower bound of the
path starting at node 2
= 25 + 17 + 11= 53

11/20/2024 67
Branch and Bound

Let us consider edge from 0 3


1. Change the elements in row 0 and column 3 and at index(3,0) to
Infinity(marked in red).

The Resulting cost matrix is :

11/20/2024 68
Branch and Bound

• Now calculate lower bound of the path starting at node 3 using the
Approach discussed earlier.
• Lower bound of the path starting at node 3 is 0 as it is already in
reduced form, i.e. all rows and all columns have zero value.

Therefore for node 3, cost will be

Cost = Cost of node 0 + cost of the edge (0,3) + Lower bound of the
path starting at node 3
= 25 + 0 + 0= 25

Similarly we calculate for 0 4. Its cost will be 31.

11/20/2024 69
Branch and Bound

• Now we find a live node with estimated cost. Live nodes 1,2,3 and 4
has costs 35, 53, 25 and 31 respectively.

• The minimum among them is node 3 having cost 25. So node 3 will
be expanded further as shown in state space tree diagram.

• After adding its children to list of live nodes, we again find a live
node with least cost and expand it.

• We continue the search till a leaf is encountered in space search tree.


If a leaf is encountered, then the tour is completed and we will
return back to the root node.

11/20/2024 70
Unit 4

Thank You

11/20/2024 71
11/20/2024 72

You might also like