0% found this document useful (0 votes)
43 views

Algorithms - CS3401 - Notes - Unit 4 - State Space Search Algorithms Stud

The document outlines various topics in computer science, including algorithms for solving the N-Queens problem, Hamiltonian cycles, subset sum problems, and graph coloring. It describes the use of backtracking techniques to find solutions for these problems and provides algorithms for implementation. Additionally, it includes examples and complexity analysis for the discussed algorithms.

Uploaded by

Nisha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Algorithms - CS3401 - Notes - Unit 4 - State Space Search Algorithms Stud

The document outlines various topics in computer science, including algorithms for solving the N-Queens problem, Hamiltonian cycles, subset sum problems, and graph coloring. It describes the use of backtracking techniques to find solutions for these problems and provides algorithms for implementation. Additionally, it includes examples and complexity analysis for the discussed algorithms.

Uploaded by

Nisha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Click on Subject/Paper under Semester to enter.

Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics GE3451
I - HS3152 - MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester

4th Semester
- MA3151 MA3251 Computer Organization
1st Semester

2nd Semester

- CS3351 Artificial Intelligence


Engineering Graphics and Machine Learning
Engineering Physics - - CS3491
- GE3251 Foundation of Data
PH3151
Science - CS3352
Database Management
Physics for
Engineering Chemistry System - CS3492
Information Science Data Structure -
- CY3151 - PH3256 CS3301

Basic Electrical and


Algorithms - CS3401
Problem Solving and Electronics Engineering Object Oriented
Python Programming - - BE3251 Programming - CS3391 Introduction to
GE3151 Operating Systems -
Programming in C -
CS3451
CS3251

Computer Networks - Object Oriented


CS3591 Software Engineering
- CCS356
Compiler Design - Human Values and
5th Semester

CS3501 Embedded Systems Ethics - GE3791


7th Semester

8th Semester
6th Semester

and IoT - CS3691


Cryptography and Open Elective 2
Cyber Security - Open Elective-1 Project Work /
CB3491
Open Elective 3 Intership
Distributed Computing Elective-3
- CS3551 Open Elective 4
Elective-4
Elective 1
Management Elective
Elective-5
Elective 2
Elective-6
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to
enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering
www.BrainKart.com Page 1 of 25

UNIT 4
Backtracking
N queen 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.

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."

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 q2 in column 3, i.e. (2, 3) but then no position is left for
placing queen 'q3' safely. So we backtrack one step and place the queen 'q2' 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). 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.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 2 of 25

The implicit tree for 4 - queen problem for a solution (2, 4, 1, 3) is as follows:

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.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 3 of 25

4 - Queens solution space with nodes numbered in DFS

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.

One possible solution for 8 queens problem is shown in fig:

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 and only if |j-l|=|i-k|

Place (k, i) returns a Boolean value that is true if the kth queen can be placed in column i. It tests both
whether i is distinct from all previous costs x1, x2,....xk-1 and whether there is no other queen on the same
diagonal.

Using place, we give a precise solution to then n- queens problem.


1. Place (k, i)
2. {
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 4 of 25

3. For j ← 1 to k - 1
4. do if (x [j] = i)
5. or (Abs x [j]) - i) = (Abs (j - k))
6. then return false;
7. return true;
8. }
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.
1. N - Queens (k, n)
2. {
3. For i ← 1 to n
4. do if Place (k, i) then
5. {
6. x [k] ← i;
7. if (k ==n) then
8. write (x [1....n));
9. else
10. N - Queens (k + 1, n);
11. }
12. }

Hamiltonian Circuit
The Hamiltonian cycle is the cycle in the graph which visits all the vertices in graph exactly once and
terminates at the starting node. It may not include all the edges

 The Hamiltonian cycle problem is the problem of finding a Hamiltonian cycle in a graph if there exists
any such cycle.

 The input to the problem is an undirected, connected graph. For the graph shown in Figure (a), a
path A – B – E – D – C – A forms a Hamiltonian cycle. It visits all the vertices exactly once, but does
not visit the edges <B, D>.

 The Hamiltonian cycle problem is also both, decision problem and an optimization problem. A
decision problem is stated as, “Given a path, is it a Hamiltonian cycle of the graph?”.

 The optimization problem is stated as, “Given graph G, find the Hamiltonian cycle for the graph.”

 We can define the constraint for the Hamiltonian cycle problem as follows:
Inanypath,vertexiand(i+1)m u@stbeeadjacuent

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 5 of 25

 1st and (n – 1)th vertex must be adjacent (nth of cycle is the initial vertex itself).

 Vertex i must not appear in the first (i – 1) vertices of any path.

 With the adjacency matrix representation of the graph, the adjacency of two vertices can be verified
in constant time.

Algorithm
HAMILTONIAN (i)
// Description : Solve Hamiltonian cycle problem using backtracking.
// Input : Undirected, connected graph G = <V, E> and initial vertex i
// Output : Hamiltonian cycle
if
FEASIBLE(i)
then
if
(i == n - 1)
then
Print V[0… n – 1]
else
j←2
while
(j ≤ n)
do
V[i] ← j
HAMILTONIAN(i + 1)
j←j+1
end
end
end
function
FEASIBLE(i)
flag ← 1
for
j ← 1 to i – 1
do
if
Adjacent(Vi, Vj)
then
flag ← 0
end
end
if
Adjacent (Vi, Vi-1)
then
flag ← 1
else
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 6 of 25

flag ← 0
end
return
flag

Complexity Analysis
Looking at the state space graph, in worst case, total number of nodes in tree would be,
T(n) = 1 + (n – 1) + (n – 1)2 + (n – 1)3 + … + (n – 1)n – 1
=frac(n−1)n–1n–2
T(n) = O(nn). Thus, the Hamiltonian cycle algorithm runs in exponential time.

Example: Find the Hamiltonian cycle by using the backtracking approach for a given graph.

The backtracking approach uses a state-space tree to check if there exists a Hamiltonian cycle in the graph.
Figure (g) shows the simulation of the Hamiltonian cycle algorithm. For simplicity, we have not explored all
possible paths, the concept is self-explanatory. It is not possible to include all the paths in the graph, so few
of the successful and unsuccessful paths are traced in the graph. Black nodes indicate the Hamiltonian cycle.

Subset Sum Problem


https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 7 of 25

Sum of Subsets Problem: Given a set of positive integers, find the combination of numbers that sum to given
value M.
Sum of subsets problem is analogous to the knapsack problem. The Knapsack Problem tries to fill the
knapsack using a given set of items to maximize the profit. Items are selected in such a way that the total
weight in the knapsack does not exceed the capacity of the knapsack. The inequality condition in the
knapsack problem is replaced by equality in the sum of subsets problem.
Given the set of n positive integers, W = {w1, w2, …, wn}, and given a positive integer M, the sum of the
subset problem can be formulated as follows (where wi and M correspond to item weights and knapsack
capacity in the knapsack problem):

Where,

Numbers are sorted in ascending order, such that w1 < w2 < w3 < …. < wn. The solution is often represented
using the solution vector X. If the ith item is included, set xi to 1 else set it to 0. In each iteration, one item is
tested. If the inclusion of an item does not violet the constraint of the problem, add it. Otherwise, backtrack,
remove the previously added item, and continue the same procedure for all remaining items. The solution is
easily described by the state space tree. Each left edge denotes the inclusion of wi and the right edge
denotes the exclusion of wi. Any path from the root to the leaf forms a subset. A state-space tree for n = 3 is
demonstrated in Fig. (a).

Fig. (a): State space tree for n = 3


Algorithm for Sum of subsets
The algorithm for solving the sum of subsets problem using recursion is stated below:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 8 of 25

Examples

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 9 of 25

Graph Colouring

In this problem, an undirected graph is given. There is also provided m colors. The problem is to find if it is
possible to assign nodes with m different colors, such that no two adjacent vertices of the graph are of the
same colors. If the solution exists, then display which color is assigned on which vertex.
Starting from vertex 0, we will try to assign colors one by one to different nodes. But before assigning, we
have to check whether the color is safe or not. A color is not safe whether adjacent vertices are containing
the same color.
Input and Output
Input:
The adjacency matrix of a graph G(V, E) and an integer m, which indicates the maximum number of colors
that can be used.

Let the maximum color m = 3.


Output:
This algorithm will return which node will be assigned with which color. If the solution is not possible, it will
return false.
For this input the assigned colors are:
Node 0 -> color 1
Node 1 -> color 2
Node 2 -> color 3
Node 3 -> color 2

Algorithm
isValid(vertex, colorList, col)
Input − Vertex, colorList to check, and color, which is trying to assign.
Output − True if the color assigning is valid, otherwise false.
Begin
for all vertices v of the graph, do
if there is an edge between v and i, and col = colorList[i], then
return false
done
return true
End
https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 10 of 25

graphColoring(colors, colorList, vertex)


Input − Most possible colors, the list for which vertices are colored with which color, and the starting vertex.
Output − True, when colors are assigned, otherwise false.
Begin
if all vertices are checked, then
return true
for all colors col from available colors, do
if isValid(vertex, color, col), then
add col to the colorList for vertex
if graphColoring(colors, colorList, vertex+1) = true, then
return true
remove color for vertex
done
return false

End

Branch and Bound


Solving 15 puzzle Problem (LCBB)
The problem cinsist of 15 numbered (0-15) tiles on a square box with 16 tiles(one tile is blank or empty).
The objective of this problem is to change the arrangement of initial node to goal node by using series of
legal moves.
The Initial and Goal node arrangement is shown by following figure.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 11 of 25

1 2 4 15 1 2 3 4

2 5 12 5 6 7 8

7 6 11 14 9 10 11 12

8 9 10 13 13 14 15

Initial Arrangement Final Arrangement

In initial node four moves are possible. User can move any one of the tile like 2,or 3, or 5, or 6 to the empty
tile. From this we have four possibilities to move from initial node.
The legal moves are for adjacent tile number is left, right, up, down, ones at a time.
Each and every move creates a new arrangement, and this arrangement is called state of puzzle problem.
By using different states, a state space tree diagram is created, in which edges are labeled according to the
direction in which the empty space moves.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 12 of 25

The state space tree is very large because it can be 16! Different arrangements.
In state space tree, nodes are numbered as per the level. In each level we must calculate the value
or cost of each node by using given formula:
C(x)=f(x)+g(x),
f(x) is length of path from root or initial node to node x,
g(x) is estimated length of path from x downward to the goal node. Number of non blank tile not in
their correct position.
C(x)< Infinity.(initially set bound).
Each time node with smallest cost is selected for further expansion towards goal node. This node
become the e-node.

State Space tree with node cost is shown in diagram.

Assignment Problem
Problem Statement
Let’s first define a job assignment problem. In a standard version of a job assignment problem, there
can be jobs and workers. To keep it simple, we’re taking jobs and workers in our example:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 13 of 25

We can assign any of the available jobs to any worker with the condition that if a job is assigned to a
worker, the other workers can’t take that particular job. We should also notice that each job has
some cost associated with it, and it differs from one worker to another.
Here the main aim is to complete all the jobs by assigning one job to each worker in such a way that
the sum of the cost of all the jobs should be minimized.
Branch and Bound Algorithm Pseudocode
Now let’s discuss how to solve the job assignment problem using a branch and bound algorithm.
Let’s see the pseudocode first:

Here, is the input cost matrix that contains information like the number of available jobs, a list
of available workers, and the associated cost for each job. The function MinCost() maintains a list of
active nodes. The function Leastcost() calculates the minimum cost of the active node at each level
of the tree. After finding the node with minimum cost, we remove the node from the list of active
nodes and return it.
We’re using the add() function in the pseudocode, which calculates the cost of a particular node and
adds it to the list of active nodes.
In the search space tree, each node contains some information, such as cost, a total number of jobs,
as well as a total number of workers.
Now let’s run the algorithm on the sample example we’ve created:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 14 of 25

Advantages
In a branch and bound algorithm, we don’t explore all the nodes in the tree. That’s why the time
complexity of the branch and bound algorithm is less when compared with other algorithms.
If the problem is not large and if we can do the branching in a reasonable amount of time, it finds an
optimal solution for a given problem.
The branch and bound algorithm find a minimal path to reach the optimal solution for a given
problem. It doesn’t repeat nodes while exploring the tree.
Disadvantages
The branch and bound algorithm are time-consuming. Depending on the size of the given problem,
the number of nodes in the tree can be too large in the worst case.

Knapsack Problem using branch and bound


Problem Statement
We are a given a set of n objects which have each have a value vi and a weight wi. The objective of
the 0/1 Knapsack problem is to find a subset of objects such that the total value is maximized, and

the sum of weights of the objects does not exceed a given threshold W. An important condition here
is that one can either take the entire object or leave it. It is not possible to take a fraction of the
object.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 15 of 25

Consider an example where n = 4, and the values are given by {10, 12, 12, 18}and the weights given
by {2, 4, 6, 9}. The maximum weight is given by W = 15. Here, the solution to the problem will be
including the first, third and the fourth objects.

Here, the procedure to solve the problem is as follows are:


 Calculate the cost function and the Upper bound for the two children of each node. Here,
the (i + 1)th level indicates whether the ith object is to be included or not.
 If the cost function for a given node is greater than the upper bound, then the node need
not be explored further. Hence, we can kill this node. Otherwise, calculate the upper bound
for this node. If this value is less than U, then replace the value of U with this value. Then, kill
all unexplored nodes which have cost function greater than this value.
 The next node to be checked after reaching all nodes in a particular level will be the one with
the least cost function value among the unexplored nodes.
 While including an object, one needs to check whether the adding the object crossed the
threshold. If it does, one has reached the terminal point in that branch, and all the
succeeding objects will not be included.

Time and Space Complexity


Even though this method is more efficient than the other solutions to this problem, its worst case
time complexity is still given by O(2n), in cases where the entire tree has to be explored. However, in
its best case, only one path through the tree will have to explored, and hence its best case time
complexity is given by O(n). Since this method requires the creation of the state space tree, itsspace
complexity will also be exponential.

Solving an Example
Consider the problem with n =4, V = {10, 10, 12, 18}, w = {2, 4, 6, 9} and W = 15. Here, we calculate
the initital upper bound to be U = 10 + 10 + 12 = 32. Note that the 4th object cannot be included
here, since that would exceed W. For the cost, we add 3/9 th of the final value, and hence the cost
function is 38. Remember to negate the values after calculation before comparison.
After calculating the cost at each node, kill nodes that do not need exploring. Hence, the final state
space tree will be as follows (Here, the number of the node denotes the order in which the state
space tree was explored):

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 16 of 25

Note here that node 3 and node 5 have been killed after updating U at node 7. Also, node 6 is not
explored further, since adding any more weight exceeds the threshold. At the end, only nodes 6 and
8 remain. Since the value of U is less for node 8, we select this node. Hence the solution is {1, 1, 0, 1},
and we can see here that the total weight is exactly equal to the threshold value in this case.

Travelling salesman problem


 Travelling Salesman Problem (TSP) is an interesting problem. Problem is defined as “given n
cities and distance between each pair of cities, find out the path which visits each city
exactly once and come back to starting city, with the constraint of minimizing the travelling
distance.”
 TSP has many practical applications. It is used in network design, and transportation route
design. The objective is to minimize the distance. We can start tour from any random city
and visit other cities in any order. With n cities, n! different permutations are possible.
Exploring all paths using brute force attacks may not be useful in real life applications.
LCBB using Static State Space Tree for Travelling Salseman Problem
 Branch and bound is an effective way to find better, if not best, solution in quick time by
pruning some of the unnecessary branches of search tree.
 It works as follow:
Consider directed weighted graph G = (V, E, W), where node represents cities and weighted
directed edges represents direction and distance between two cities.
1. Initially, graph is represented by cost matrix C, where
Cij = cost of edge, if there is a direct path from city i to city j
Cij = ∞, if there is no direct path from city i to city j.
2. Convert cost matrix to reduced matrix by subtracting minimum values from appropriate rows
and columns, such that each row and column contains at least one zero entry.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 17 of 25

3. Find cost of reduced matrix. Cost is given by summation of subtracted amount from the cost
matrix to convert it in to reduce matrix.
4. Prepare state space tree for the reduce matrix
5. Find least cost valued node A (i.e. E-node), by computing reduced cost node matrix with every
remaining node.
6. If <i, j> edge is to be included, then do following :
(a) Set all values in row i and all values in column j of A to ∞
(b) Set A[j, 1] = ∞
(c) Reduce A again, except rows and columns having all ∞ entries.
7. Compute the cost of newly created reduced matrix as,
Cost = L + Cost(i, j) + r
Where, L is cost of original reduced cost matrix and r is A[i, j].
8. If all nodes are not visited then go to step 4.
Reduction procedure is described below :
Raw Reduction:
Matrix M is called reduced matrix if each of its row and column has at least one zero entry or entire
row or entire column has ∞ value. Let M represents the distance matrix of 5 cities. M can be
reduced as follow:
MRowRed = {Mij – min {Mij | 1 ≤ j ≤ n, and Mij < ∞ }}
Consider the following distance matrix:

Find the minimum element from each row and subtract it from each cell of matrix.

Reduced matrix would be:

Row reduction cost is the summation of all the values subtracted from each rows:
Row reduction cost (M) = 10 + 2 + 2 + 3 + 4 = 21
Column reduction:
Matrix MRowRed is row reduced but not the column reduced. Matrix is called column reduced if each
of its column has at least one zero entry or all ∞ entries.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 18 of 25

MColRed = {Mji – min {Mji | 1 ≤ j ≤ n, and Mji < ∞ }}


To reduced above matrix, we will find the minimum element from each column and subtract it from
each cell of matrix.

Column reduced matrix MColRed would be:

Each row and column of MColRed has at least one zero entry, so this matrix is reduced matrix.
Column reduction cost (M) = 1 + 0 + 3 + 0 + 0 = 4
State space tree for 5 city problem is depicted in Fig. 6.6.1. Number within circle indicates the order
in which the node is generated, and number of edge indicates the city being visited.

Example
Example: Find the solution of following travelling salesman problem using branch and bound
method.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 19 of 25

Solution:
 The procedure for dynamic reduction is as follow:
 Draw state space tree with optimal reduction cost at root node.
 Derive cost of path from node i to j by setting all entries in ith row and jth column as ∞.
Set M[j][i] = ∞
 Cost of corresponding node N for path i to j is summation of optimal cost + reduction cost +
M[j][i]
 After exploring all nodes at level i, set node with minimum cost as E node and repeat the
procedure until all nodes are visited.
 Given matrix is not reduced. In order to find reduced matrix of it, we will first find the row
reduced matrix followed by column reduced matrix if needed. We can find row reduced
matrix by subtracting minimum element of each row from each element of corresponding
row. Procedure is described below:
 Reduce above cost matrix by subtracting minimum value from each row and column.

M‘1

is not reduced matrix. Reduce it subtracting minimum value from corresponding column. Doing this
we get,

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 20 of 25

Cost of M1 = C(1)
= Row reduction cost + Column reduction cost
= (10 + 2 + 2 + 3 + 4) + (1 + 3) = 25
This means all tours in graph has length at least 25. This is the optimal cost of the path.
State space tree

Let us find cost of edge from node 1 to 2, 3, 4, 5.


Select edge 1-2:
Set M1 [1] [ ] = M1 [ ] [2] = ∞
Set M1 [2] [1] = ∞
Reduce the resultant matrix if required.

M2 is already reduced.
Cost of node 2 :
C(2) = C(1) + Reduction cost + M1 [1] [2]
= 25 + 0 + 10 = 35
Select edge 1-3
Set M1 [1][ ] = M1 [ ] [3] = ∞
Set M1 [3][1] = ∞
Reduce the resultant matrix if required.

Cost of node 3:
C(3) = C(1) + Reduction cost + M1[1] [3]
= 25 + 11 + 17 = 53

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 21 of 25

Select edge 1-4:


Set M1 [1][ ] = M1[ ][4] = ∞
Set M1 [4][1] = ∞
Reduce resultant matrix if required.

Matrix M4 is already reduced.


Cost of node 4:
C(4) = C(1) + Reduction cost + M1 [1] [4]
= 25 + 0 + 0 = 25
Select edge 1-5:
Set M1 [1] [ ] = M1 [ ] [5] = ∞
Set M1 [5] [1] = ∞
Reduce the resultant matrix if required.

Cost of node 5:
C(5) = C(1) + reduction cost + M1 [1] [5]
= 25 + 5 + 1 = 31
State space diagram:

Node 4 has minimum cost for path 1-4. We can go to vertex 2, 3 or 5. Let’s explore all three nodes.
Select path 1-4-2 : (Add edge 4-2)
Set M4 [1] [] = M4 [4] [] = M4 [] [2] = ∞
Set M4 [2] [1] = ∞
Reduce resultant matrix if required.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 22 of 25

Matrix M6 is already reduced.


Cost of node 6:
C(6) = C(4) + Reduction cost + M4 [4] [2]
= 25 + 0 + 3 = 28
Select edge 4-3 (Path 1-4-3):
Set M4 [1] [ ] = M4 [4] [ ] = M4 [ ] [3] = ∞
Set M [3][1] = ∞
Reduce the resultant matrix if required.

M‘7

is not reduced. Reduce it by subtracting 11 from column 1.

Cost of node 7:
C(7) = C(4) + Reduction cost + M4 [4] [3]
= 25 + 2 + 11 + 12 = 50
Select edge 4-5 (Path 1-4-5):

Matrix M8 is reduced.
Cost of node 8:
C(8) = C(4) + Reduction cost + M4 [4][5]
= 25 + 11 + 0 = 36
State space tree

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 23 of 25

Path 1-4-2 leads to minimum cost. Let’s find the cost for two possible paths.

Add edge 2-3 (Path 1-4-2-3):


Set M6 [1][ ] = M6 [4][ ] = M6 [2][ ]
= M6 [][3] = ∞
Set M6 [3][1] = ∞
Reduce resultant matrix if required.

Cost of node 9:
C(9) = C(6) + Reduction cost + M6 [2][3]
= 28 + 11 + 2 + 11 = 52
Add edge 2-5 (Path 1-4-2-5):
Set M6 [1][ ] = M6 [4][ ] = M6 [2][ ] = M6 [ ][5] = ∞
Set M6 [5][1] = ∞
Reduce resultant matrix if required.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 24 of 25

Cost of node 10:


C(10) = C(6) + Reduction cost + M6 [2][5]
= 28 + 0 + 0 = 28
State space tree

Add edge 5-3 (Path 1-4-2-5-3):

Cost of node 11:


C(11) = C(10) + Reduction cost + M10 [5][3]
= 28 + 0 + 0 = 28

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
www.BrainKart.com Page 25 of 25

State space tree:

So we can select any of the edge. Thus the final path includes the edges <3, 1>, <5, 3>, <1, 4>, <4, 2>,
<2, 5>, that forms the path 1 – 4 – 2 – 5 – 3 – 1. This path has cost of 28.

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes&hl=en_IN
Click on Subject/Paper under Semester to enter.
Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics GE3451
I - HS3152 - MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester

4th Semester
- MA3151 MA3251 Computer Organization
1st Semester

2nd Semester

- CS3351 Artificial Intelligence


Engineering Graphics and Machine Learning
Engineering Physics - - CS3491
- GE3251 Foundation of Data
PH3151
Science - CS3352
Database Management
Physics for
Engineering Chemistry System - CS3492
Information Science Data Structure -
- CY3151 - PH3256 CS3301

Basic Electrical and


Algorithms - CS3401
Problem Solving and Electronics Engineering Object Oriented
Python Programming - - BE3251 Programming - CS3391 Introduction to
GE3151 Operating Systems -
Programming in C -
CS3451
CS3251

Computer Networks - Object Oriented


CS3591 Software Engineering
- CCS356
Compiler Design - Human Values and
5th Semester

CS3501 Embedded Systems Ethics - GE3791


7th Semester

8th Semester
6th Semester

and IoT - CS3691


Cryptography and Open Elective 2
Cyber Security - Open Elective-1 Project Work /
CB3491
Open Elective 3 Intership
Distributed Computing Elective-3
- CS3551 Open Elective 4
Elective-4
Elective 1
Management Elective
Elective-5
Elective 2
Elective-6
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to
enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering

You might also like