0% found this document useful (0 votes)
3 views85 pages

DS Unit4 Graphs

Uploaded by

buffertimeplay
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
3 views85 pages

DS Unit4 Graphs

Uploaded by

buffertimeplay
Copyright
© © All Rights Reserved
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/ 85

Unit 4 Graphs

Dr.A.Thomas Paul Roy


Professor, Dept. of CSE.,
PSNA CET.

Syllabus
Graph Terminologies
Topological Sort
Graph Traversals
Breadth first traversal
Depth First Traversal
Minimum Spanning Trees
Prims’ and Kruskal algorithm
Shortest Path Algorithms
Dijikstra’s Algorithm
Bellman Ford Algorithm
Floyds’ Warshall Algorithm
Graph Applications

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Course Outcome

CO4: Apply graph data structure to


solve real life problems

Introduction
Terms to be remembered
Graph, Ways of representation
Sub Graph
Symmetric Digraph / Undirected Graph
Complete Graph
Degree, Incidence, Adjacency, Path
Connected Graph / Strongly Connected Graph
Cycle, acyclic graph
Connected component
Weighted graph

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Graph
“Graph” is non-linear data structure where the
data items are stored in a memory locations by
means of pointer

“Graph” can be defined as a set of 2 tuples such


that G=(V,E)
Where G = Graph
V = Vertices
E = Edges of a graph

Introduction
Graph
“Graph” is a collection of nodes / objects called
vertices and edges where vertices are a data
element of the graph & edge is a path between 2
nodes

“Graph” is non-linear data structure that is used


to represent a relational data.
Example: Road map of all cities in a country.
Such complex relationship can be easily
defined using Graph Algorithms

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Graph
“Graph” is a finite set of points (vertices or
nodes), some of which are connected by lines
or arrows (edges)

Introduction
Graph Representation - 2 ways
1. Undirected Graph
2. Directed Graph

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Edge between 2 nodes are not
Directional oriented. It is bidirectional
Undirected Graph

A A

B C B C
Fig. 1 Fig. 2

Vertices = {A, B, C}
Edges = {(A,B), (A,C), (B,C)} D

Vertices = {A, B, C, D}
Edges = {(A,B), (A,C), (A,D),(B,D),(B,C),(C,D)}

Introduction
Edge between 2 nodes are
Directional oriented. It is Unidirectional
Directed Graph
A A

B C B C
Fig. 1 Fig. 2

Vertices = {A, B, C}
Edges = {(A,B), (A,C), (B,C)} D

Vertices = {A, B, C, D}
Edges = {(A,B), (A,C), (D,A),(B,C),(D,B),(D,C)}

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Note
Any complex problems can be solved using
Graph algorithms

Number of possible edges in an Undirected


graph is “n(n-1)/2”

Number of possible edges in an Directed graph


is “n2”

Complexity of Graph algorithms falls into (n2)

Introduction
Example 1: Find the total number of possible
edges from a given directed graph

A A B

B C C D
Fig. 1 Fig. 2

n(n-1) ? n = total number of nodes


2

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Example 2 Find the total number of possible edges
from a given directed graph

A
A

B C
B C Fig. 2

Fig. 1
D

n2 ? n = total number of nodes

Introduction
Sub graph
A Subgraph of a Graph, G = (V,E), is a graph G’
= (V’,E’) such that V’ V and E’ E
1 1
Example

2 3 2

Fig. 1 Fig. 2

4 3

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Sub graph
A Subgraph of a fig. 1
1 2 3

1
2 3 4

Fig. 1a Fig. 1b
2 3

Fig. 1c
4

Introduction
Sub graph
A Subgraph of a fig. 2
2 1 1

3 2 2

Fig. 2a Fig. 2b

Fig. 2c

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Symmetric Digraph
A “Symmetric Digraph” is a directed graph such
that for every edge ‘vw’ there is also a reverse
edge

Example

Introduction
Symmetric undirected graph
Every Undirected Graph is a Symmetric
undirected graph

Example
1 In Undirected graph, each edge
Facilitates bidirectional path

Edge = {(1,3),(3,1)}
2 3

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Complete Graph
It is a (normally undirected) graph with an edge
between each pair of vertices

Example
A B A B

C D C D

Fig. 1 Not a Complete Graph Fig. 2 Complete Graph

Introduction
Degree, Incidence & Adjacency
Incidence
If there is a edge between the vertices, then
that edge is said to be incident to those
vertices

10

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Degree, Incidence & Adjacency
Degree
It is the number of edges incident to a vertex
Example
A Vertex “A” has:
In-degree : 1
Out-degree: 2
Degree :3
B C
Vertex “C” ?

Introduction
Degree, Incidence & Adjacency
Adjacency
A vertex “A” is adjacent to “B” if there is a
edge from “B” to “A”

A
Here “A” is a Successor
“B” is a Predecessor
B C

11

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Path
A path from “v” to “w” of a Graph, G=(V,E), is a
sum of sequence of edges, v0v1,v1v2,…vk-1vk
vertex.
Path Length = No. of edges traversed

A path length from “A”


B C to “D” is 2

Introduction
Connected Graph
An undirected Graph is said to be connected if
there is a edge between vertices

12

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Strongly Connected Graph
A Directed Graph is said to be Strongly
connected (traveling the one-way street in their
correct direction) if there is a path from ‘v’ to
‘w’
A

B C

Introduction
Cycle
A path from a node to itself is called “Cycle”

i.e., a cycle is a path in which the initial and final


vertices are same

Applies to both kinds of graph

13

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Cycle
Example

Here
B C Cycle = (A, B, C, A)
Cycle = ?
D

Introduction
Acyclic Graph
A graph is said to be Acyclic if it has no cycles

B C

14

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Connected Component
Maximal connected Subgraph of Graph ‘G’
1
1

2 3
2 3

4
4

Among the set of subgraphs, maximal collection of nodes with edge

Introduction
Weighted Graph
A “weighted Graph” is a triple (V,E,W) where
(V,E) is a Graph (Directed / Undirected) and ‘W’
is weight of an edge between vertices

10
A B

15 5 20

C D
25

15

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Graph Representation – 2 kinds
1. Adjacency Matrix Representation
2. Adjacency List Representation

Introduction
Adjacency Matrix Representation
A Graph, ‘G’ can be represented by an ‘n x n’
matrix, A = aij called Adjacency Matrix for ‘G’

A.M., ‘A’ for un-weighted graph is defined by:

1 if vi is adjacent to vj E
aij = for 1 i, j n
0 otherwise

16

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Adjacency Matrix Representation
A.M., ‘A’ for weighted graph is defined by:

W(vi, vj) if vi is adjacent to vj E


aij = for 1 i, j n
c otherwise

C = constant, whose value is depends on wts. of the given problem

Ex: C = œ if the weight is considered as a cost


C=0 if the weight is considered as capacities

Introduction
Adjacency List Representation
In this representation, vertex are indexed by
linked list

17

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Example 1
Construct the adjacency matrix & list
representation for the given graph

1 2

3 4

5 6 7

Introduction
Solution
Total number of nodes = 7

Adjacency Matrix: create ‘n x n’ matrix. So,


7 x 7 Matrix is created

18

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Solution
1 2 3 4 5 6 7
1 0 1 1 0 0 0 0
2 1 0 1 1 0 0 0
3 1 1 0 1 0 1 0
4 0 1 1 0 0 1 0
5 0 0 0 0 0 1 0
6 0 0 1 1 1 0 1
7 0 0 0 0 0 1 0

Introduction
Solution
1 Adjacency
2 List: 3 NIL
Total number of nodes = 7
2 1 3 4 NIL

3 1 2 4 6 NIL

4 2 3 6 NIL

5 6 NIL

6 3 4 5 7 NIL

7 6 NIL

19

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Example 2
Construct the adjacency matrix & list
representation for the given graph
25
1 2
10
5 14 6

3 18 4
16 32
42 11
5 6 7

14

Introduction
Solution
Total number of nodes = 7

Adjacency Matrix: create ‘n x n’ matrix. So,


7 x 7 Matrix is created

20

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Solution
1 2 3 4 5 6 7
1 0 25 œ œ œ œ œ
2 œ 0 10 14 œ œ œ
3 5 œ 0 œ œ 16 œ
4 œ 6 18 0 œ œ œ
5 œ œ œ œ 0 œ œ
6 œ œ œ 32 42 0 14
7 œ œ œ œ œ 11 0

Introduction
Solution
1 Adjacency
2 25 List:
NIL
Total number of nodes = 7
2 3 10 4 14 NIL

3 1 5 6 16 NIL

4 2 6 3 18 NIL

5 NIL

6 3 32 5 42 7 14 NIL

7 6 11 NIL

21

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Introduction
Graph Applications
Any type of complex problems can be solved
using Graph Algorithms.
Air Line Route Map
Flow Charts – Directed Graph
Binary Relation
Computer Networks
Electrical Circuits

Graph Traversal
Key points to be remembered
Graph Traversal
It is a problem of visiting all nodes in the
Graph “G” in a particular manner

Traversing a Graph is the efficient way to


visit each vertex and edge exactly once

22

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Graph Traversal
Key points to be remembered
A more general form is to determine for a given
starting vertex v V all vertices such that there
is a path from v to u

“Graph Traversal” starts at initial vertex and


visits each vertex exactly once and finally
reaches end vertex

Searching a vertex in a graph can be solved by


starting at vertex “v” and systematically
searching the graph “G” for vertices that can be
reached from “u”

Graph Traversal
Key points to be remembered: Types
Let G=(V,E) be a given Graph and a vertex
“V(G)”. If we wish to visit all vertices of a
Graph “G”.

Classified into 2 types


1. Breadth First Search & Traversal
2. Depth first search & Traversal

23

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Graph Traversal
Breadth First Search & Traversal
Concept
It starts from any arbitrary vertex of a given
graph

Visits all vertices of a graph adjacent to its


starting vertex

Then it visits all unvisited vertex

This process is repeated until no vertex is


left

Breadth First Search &


Traversal
Key points to be remembered
It is a recursive algorithm, analogous to level
by level traversal of an ordered tree

If the traversal Process has just visited a


vertex “v” then it next visits all the vertices
adjacent to “v”. Continue the same process
until all the vertices of a graph visited once

Backtracking does not exist in BFS

24

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Breadth First Search &
Traversal
Procedure
Starts at initial vertex and make it as having
been visited
The vertex V at this time said to be unexplored
The vertex V is said to be explored, if its
adjacent vertices are visited
All unvisited vertices adjacent from V are
visited next – these vertices are unexplored
vertices
The newly visited vertices have not been
explored and are put on to the end of a list of
unexplored vertices
Exploration continues until no unexplored
vertex is left

Breadth First Search &


Traversal
Use of Queue
“Queue” is used to trace the BFS

Queue is initialized with traversals starting


vertex, which is marked as visited

The unvisited vertices that are adjacent to the


front vertex are marked as visited and it is
added to queue

The front vertex is removed from the queue

25

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Breadth First Search &
Traversal
Steps to be followed
1. Start the traversal process from starting
vertex “v”

2. Select an unvisited vertices adjacent to “v”

3. Unvisited vertices adjacent to these newly


visited vertices are then visited

Breadth First Search &


Traversal
Problem 1: Apply BFS algorithm to visit all the
vertices of a given Graph

1 2

3 4 5 6

26

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Breadth First Search &
Traversal
Solution 1:
Starting vertex
0

1 2

3 4 5 6

Vertices visiting sequence: 0,1,2,3,4,5,6,7

Breadth First Search &


Traversal
Problem 2: Apply BFS algorithm to visit all the
vertices of a given Graph

A D

B
G

F C E

27

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Breadth First Search &
Traversal
Problem 3: Apply BFS algorithm to visit all the
vertices of a given Graph

1 A

2 4 B C

3 D

Breadth First Search &


Traversal
Problem 4: Apply BFS algorithm to visit all the
vertices of a given Graph
A B G

C D F H

28

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Depth First Search &
Traversal
Key points to be remembered
“DFS” is a recursive algorithm, which is
analogous to preorder traversal of a tree

Traversal Process must start from any starting


vertex “v”

Suppose that the traversal has just visited a


vertex “v” and let w0, w1, w2,…,wk be the
vertices adjacent to vertex “v”

Then we shall next visit w0 and keep w1,


w2,…,wk waiting

Depth First Search &


Traversal
Key points to be remembered
After visiting w0, we traverse all the vertices
which is adjacent to it. Continue the process
until all the vertices of a Graph gets visited
once

During Traversal, If path exists from one node


to another node visit / walk across the edge
(explore the edge) as per non-decreasing
order

29

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Depth First Search &
Traversal
Key points to be remembered
If path does not exist from one node to other
node, return to a previous node where we
have been before – Backtracking

Traversal Tree should not form a cycle

Constraints

Depth First Search &


Traversal
Steps to be followed
1. Start the traversal process from starting
vertex “v” and make it is visited

2. On each iteration, algorithm proceeds with


unvisited vertex. For ex.: Select an unvisited
vertex “w” which is adjacent to “v” & a depth
first traversal from “w” is initiated

3. Repeat the step 2 for all adjacent

4. Process will stop when a vertex “v” is reached


such that all its adjacent vertices are visited
once.

30

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Depth First Search &
Traversal
Problem 1: Apply DFS algorithm to visit all the
vertices of a given Graph

A D

B
G

F C E

Depth First Search &


Traversal
Solution 1:
Proceed with non-decreasing order
Starting Vertex Forms Cycle-
A D Delete that visiting
B

Backtracks to B – A
And explore A to F
F C

FromFrom
F, it isc possible
–”DeadtoEnd”-
traverse to A
there isor
noCadjacent
– vertices
both Algorithm
are discovered nodes – Fto
Backtracks is referred as Dead End
old solution
select next adjacent vertex

31

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Depth First Search &
Traversal
Stack Representation
Stack is used to trace the operation of DFS

Push the vertex on to the stack, when the


vertex is reached for the first time

Pop a vertex from stack when it becomes dead


end

A D
B
G

F C E

Solution 1: using Stack (Syllabus)

C D
B B B B
A A A A A
Push A Push B Push C Pop C Push D
C – Dead End
Pop Occurs

32

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Depth First Search &
Traversal
Solution 1: using Stack (Syllabus)

D
B B F
A A A A A
Pop D Pop B Push F Pop F Pop A
Forms Cycle
Traversal stops F – Dead End
It goes to B then to A Pop Occurs

Depth First Search &


Traversal
Problem 2: Apply DFS algorithm to visit all the
vertices of a given Graph

1 2

3 4 5 6

33

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Depth First Search &
Traversal
Starting vertex

0
Visiting vertex sequence is
0,1,3,7,4,5,2,6
1 2

3 4 5 6

vertex “4” has an edge to vertex “1”


That has been visited already –
Backtracking occurs to its previous node

Depth First Search &


Traversal
Problem 3: Apply DFS algorithm to visit all the
vertices of a given Graph [Start @ h]

b c d

e f g

h i

34

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
BFS Vs. DFS
S.No. Factors DFS BFS
1 Data Structures Stack Queue
2 Conceptual Builds the Analogous to preorder
tree level by
level
3 Backtracking No uses

4 Applications Connectivity, Connectivity, Cyclicity


Cyclicity, and and minimum edge
articulation path
points

5 Efficiency (|V2|) (|V2|)

Shortest Path Algorithm


Key points to be remembered
One of the application of the Graph Problems

Mostly Applicable to Weighted Graph

In a weighted Graph, it is desired to find the


shortest path between nodes

Example: path between the node ‘s’ & ‘t‘

“Shortest path” is defined as a path from node


‘s’ to ‘t’ such that the sum of the weights of the
arcs or edges on the path is minimized

35

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Shortest Path Algorithm
Key points to be remembered
From the given weighted Graph, G={V,E,W}, it
is needed to find a path from one vertex to
other vertex such that the sum of weights on
the path is as small as possible. Such path
can be referred as “Shortest Path”

The “shortest path” problem is the problem of


finding a path between two vertices (or nodes)
such that the sum of the weights of its
constituent edges is minimized

Shortest Path Algorithm


Key points to be remembered
Assume, a person wants to move from
0
5 2 Vertex “0” to “1”. The set of possible
paths are:
1 2 2 0–1
6 7 0–2–3–1
3 10 0–2–1
25
14 0–2–5–6–4–1
12
4 5

11 15
6
Among those possible paths, “0-2-1”
is the shortest path whose length is “4”

36

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Shortest Path Algorithm
Key points to be remembered
Note: For non-weighted Graph, Shortest path
can be identified based on the path length

Shortest Path Algorithm


Key points to be remembered
2 ways – shortest path algorithm may be
considered
1. Single source shortest path problem
2. All pairs shortest path problem

37

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Shortest Path Algorithm
Key points to be remembered
Single source shortest path problem
Given as input a graph “G={V,E}” and a
distinguished vertex “s”, Shortest path can
be calculated from “s” to every other vertex
in “G”

All Pairs shortest path problem


Given a input Graph “G={V,E}”, the shortest
path is calculated between every pair of
vertices in G

Shortest Path Algorithm


Key points to be remembered
Example
Dijkstra Algorithm

38

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Dijkstra Algorithm
Key points to be remembered
This algorithm is conceived by Dutch
computer scientist “Edsger Dijkstra” in
1959,

It is a graph search algorithm that solves


the single-source shortest path problem
for a graph with nonnegative edge path
costs, producing a shortest path tree

Dijkstra Algorithm
Key points to be remembered
Single Source Shortest path problem

This algorithm applicable to Graphs with


non-negative weights

This algorithm ask us to determine the


shortest path from the source vertex to other
vertices in a given graph

i.e., for the given source vertex in a graph “G”,


find shortest path to all other vertices

39

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Dijkstra Algorithm
Key points to be remembered
For a given source vertex (node) in the graph,
the algorithm finds the path with lowest cost
(i.e. the shortest path) between that vertex and
every other vertex

Dijkstra Algorithm
Key points to be remembered
Example
if the vertices of the graph represent cities
and edge path costs represent driving
distances between pairs of cities connected
by a direct road, Dijkstra's algorithm can be
used to find the shortest route between one
city and all other cities

40

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Dijkstra Algorithm
Dindigul Source Vertex

50
67
kujiliumparai
Madurai

35 25
57

karur 50
110
Vedasandur Dijkstra algorithm
Helps to find shortest path

Palani

Dijkstra Algorithm
Problem 1
Find Shortest path using Dijkstra algorithm?
[Use vertex ‘a’ as source]

4
b c

3
5 6
2

a d e
7 4

41

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Solution 1
Dijkstra Algorithm

Tree Remaining Vertices Illustration


Vertices
a(-,0) b(a,3), c(-, œ), d(a,7), b
c(-, œ) a

b(a,3) c(b,3+4), e(-, œ), b


d(b,3+2) a
d
d(b,5) c(b,3+4), e(d,3+2+4) b c
a
d
c(b,7) e(d,9)
b c
a
d e

Dijkstra Algorithm
Note
In general, the algorithm already has identified
the shortest path to i-1 other vertices nearest
to the source

These i-1 vertices, source vertex and the


edges of its shortest path from source forms a
subtree ‘T’

The next nearest vertex to the source can be


found among all vertices adjacent to vertices
Ti. The set of vertices nearer to Ti is referred
as “Fringe Vertices”

42

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Dijkstra Algorithm
Problem 2
Find Shortest path using Dijkstra algorithm?
[Use vertex ‘a’ as source]

1
a b
5 2
c 3 d

Dijkstra Algorithm
Problem 3
Find Shortest path using Dijkstra algorithm?
[Use vertex ‘a’ as source]
1
b c
3
4 4 6

a f d
5 5
2
6 8
e

43

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Dijkstra Algorithm
Problem 4
Find Shortest path using Dijkstra algorithm?
[Use vertex ‘D’ as source]
4
A B
2
15 17

C D E
23
9 5 11
F G
13

Dijkstra Algorithm
function Dijkstra(Graph, source)
for each vertex v in Graph: // Initializations
dist[v] := infinity // Unknown distance function from
//source to v
previous[v] := undefined // Previous node in optimal path
//from source
dist[source] := 0 // Distance from source to source
Q := the set of all nodes in Graph
// All nodes in the graph are unoptimized - thus are in Q
while Q is not empty: // The main loop
u := vertex in Q with smallest dist[ ]
if dist[u] = infinity:
break // all remaining vertices are inaccessible from
source
remove u from Q

44

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Dijkstra Algorithm
for each neighbor v of u: / where v has not yet been removed from Q.
alt := dist[u] + dist_between(u, v)
if alt < dist[v]: // Relax (u,v,a)
dist[v] := alt
previous[v] := u
return previous[ ]

Minimum Spanning Tree


Key points to be remembered
Also referred as Minimum Weight Spanning
Tree

A “Spanning Tree” of the graph is a subgraph,


which is a tree and connects all the vertices
together with the minimum weight

“Spanning Tree” of connected Graph is its


connected acyclic subgraph (tree) that
contains all vertices of the graph

45

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Minimum Spanning Tree
Key points to be remembered
A “Minimum Spanning Tree” of weighted
connected graph is its subtree of the smallest
weight where weights of the tree is defined as
sum of the weights on all its edges

Can be constructed by using 2 algorithms


1. Prims algorithm
2. Kruskal algorithm

Prims Algorithm
Key points to be remembered
It is a “greedy technique” for constructing a
Minimum Spanning Tree of a weighted
connected Graph.

This algorithm works by attaching a new node


of smallest weight to a previously constructed
subtree

46

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Greedy Technique
This technique suggests to construct a
solution to a problem thro’ the sequence of
steps each expands a partially constructed
solution until a complete solution is reached

On each successive step, a partial solution


may be
Feasible solution
Locally Optimal
Irrevokable

Prims Algorithm
Greedy Technique
Feasible Solution
Possible Solutions of the given problem that
has to satisfy the problem constraints

Locally Optimal
It is the solution that has to be the best
among all the feasible choices available

Irrevocable
Once made, it can not be changed on
subsequent steps of the algorithm

47

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Greedy Technique
The main objective of Prim’s algorithm is to
construct a Minimum Spanning Tree of the
given weighted connected graph

Prims Algorithm
Greedy Technique
There are 2 obstacles faced when you
constructing M.S.T.
Number of subtrees grows exponentially
with the graph size

Generating all subtrees for a given graph is


not easy

48

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Greedy Technique
For the best illustration, consider a Graph with
4 vertices namely: a, b, c and d
1

a b
2
5

c 3 d

Prims Algorithm
Greedy Technique
Construct a sub graph / sub tree
1 1 1
a b a b a b
2 2
5 5
c d c d c d
3 3
Fig. 1 Fig. 2 Fig. 3
Total Weight = 6 Total Weight = 8 Total Weight = 9

Among the set of subgraphs, Fig. 1 yields a Minimum Spanning Tree


cos’ it is a Subgraph of the given graph that connects all the vertices
of a Graph with smaller weight

49

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Greedy Technique
With reference to the definition of Prims
algorithm, it constructs M.S.T. of a given
weighted connected Graph thro’ the sequence
of steps of expanding sub trees

The initial subtree in a sequence has a single


vertex from the set of vertices of the given
Graph

Prims Algorithm
Greedy Technique
On each successive iteration of an algorithm,
tree is expanded by attaching a vertex to a
previously constructed solution closest to the
vertices already in a tree by “Greedy
approach”.

This algorithm stops after all graph vertices


have been included in the tree.

Algorithm takes (n-1) iterations & Running


Time of Prims algorithm is O(|E| log |V|)

50

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Example 1: Construct M.S.T using Prims
algorithm? [Use ‘0’ as the starting vertex]

0
10 28

5 1
14 16

25 6 2
24
18
12
4 3
22

Prims Algorithm
Solution Remaining Vertices
Tree Illustration
Create a table with 3 columns
Vertices
0(-,-) 1(0,28), 2(-,œ), 5(0,10), 0
3(-,œ), 4(-,œ),6(-,œ)
5

5(0,10) 1(0,28), 2(-,œ), 3(-,œ),


0
4(5,25),6(-,œ)
5

51

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Tree Remaining Vertices Illustration
Vertices
4(5,25) 1(0,28), 2(-,œ), 3(4,22), 0
6(4,24) 5

4 3
3(4,22) 1(0,28), 2(3,12), 6(3,18) 0
5
2
4 3

Prims Algorithm
Tree Remaining Vertices Illustration
Vertices 0
1
2(3,12) 1(2,16), 6(3,18) 5
2
4 3
1(2,16) 6(1,14)

0
1
5
6 2
4 3

52

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Example 2: Construct M.S.T using Prims
algorithm? [Use ‘A’ as the starting vertex]
A
5 2
F 2 B
6 7

25 G 10

14
12
E C
11 15
D

Prims Algorithm
Example 3: Construct M.S.T using Prims
algorithm? [Use ‘a’ as the starting vertex]

1
b c
3 4 6
4
a f d
5 5
2
6 8
e

53

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Prims Algorithm
Pseudo Code: Prim(G)

//prim’s algorithm for constructing a M.S.T.


Input: A weighted Connected Graph G={V,E}
Output: ET, Set of edges composing a M.S.T. of
“G”

Prims Algorithm
Pseudo Code: Prim(G)

VT = {V0} // set of tree edges can be initialized


ET = Ø
for i = 1 to |V|-1 do
find a Min. weight edge e*=(v*,u*) among all edges (v, u)
VT=VT U {u*}
ET=ET U {e*}
return ET

54

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Kruskal Algorithm
Key points to be remembered
It is an algorithm to construct M.S.T. of the
given Graph with the help of Greedy Approach
thro the Greedy Inclusion of vertex to the
vertices already in the tree

This algorithm will always yields “Optimal


Solution”

Running Time of this algorithm is O(|E| log |V|)


In worst case, it falls into O(|E| log |E|)

Kruskal Algorithm
Key points to be remembered
This algorithm begins by sorting the given
graph edges in Non-decreasing order based
on their weights.

It builds Minimum cost spanning tree by


adding edges to already constructed tree “T”
at one time such that it should not form a
cycle with the edges that are already in a
M.S.T.

constraint

55

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Kruskal Algorithm
Key points to be remembered
Consider a Graph “G” that has n>0 vertices
from which exactly n-1 edges will be selected
for inclusion in “T”

There are 2 functions that is to be performed


on the set of vertices in a Graph “G” while
constructing M.S.T, which are:
Determine an edge with minimum cost –
include it
Delete the edge

Kruskal Algorithm
Problem 1: Construct M.S.T using Kruskal
algorithm?

1
b c
3
4 4 6

a f d
5 5
2
6 8
e

56

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Kruskal Algorithm
Solution 1:
Step 1: Sort the given edges of a Graph in
Non-decreasing order
1
b c
3
4 4 6

a f d
5 5
2
6 8
e

Edge bc ef ab bf cf af df ae cd de
Wt. 1 2 3 4 4 5 5 6 6 8

Kruskal Algorithm
Key points to be remembered
Step 2: Construct M.S.T.
During this process, scan the sorted list
from lower weight value
2 functions has to be implemented
o Include the edge to a Tree if there is no
cycle

o Delete a edge if there is a cycle

57

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Kruskal Algorithm
Key points to be remembered

Selected Tree Function Resultant M.S.T


Edge Involved
bc Inclusion c
b
ef Inclusion
b c

Kruskal Algorithm
Selected Tree Function Resultant M.S.T
Edge Involved
ab Inclusion b c

a f

b c
bf Inclusion
a f

58

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Selected Tree Function Resultant M.S.T
Edge Involved

b c
cf Inclusion – forms
a cycle – delete a f
the edge

af Inclusion – forms c
b
a cycle – delete
the edge a f

Selected Function Resultant M.S.T


Tree Edge Involved
df Inclusion –

b c

a f d

ae Inclusion – e
forms a cycle
– delete the
edge

59

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Selected Function Resultant M.S.T
Tree Edge Involved
cd Inclusion –
b c
forms a cycle
– delete the a f d
edge
e

de Inclusion –
forms a cycle
– delete the
edge

Kruskal Algorithm
Problem 2: Construct M.S.T using Kruskal
algorithm?

2
b c
4
3 10
1
7
a f d
2

8 4
5 6

b c
1

60

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Kruskal Algorithm
Problem 3: Construct M.S.T using Kruskal
algorithm?
5
a b

2 3
7 6
e
4 5

c d
4

Shortest Path Algorithm


Key points to be remembered
From the given weighted Graph, G={V,E,W}, it is
needed to find a path from one vertex to other
vertex such that the sum of weights on the path
is as small as possible. Such path can be
referred as “Shortest Path”

The “shortest path” problem is the problem of


finding a path between two vertices (or nodes)
such that the sum of the weights of its
constituent edges is minimized

61

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Shortest Path Algorithm
Key points to be remembered
2 ways – shortest path algorithm may be
considered
1. Single source shortest path problem
a) Dijkstra Algorithm
b) Bellman - Ford Algorithm

2. All pairs shortest path problem


a) Floyds Warshall Algorithm

Shortest Path Algorithm


Key points to be remembered
Single source shortest path problem
Given as input a graph “G={V,E}” and a
distinguished vertex “s”, Shortest path can
be calculated from “s” to every other vertex
in “G”

All Pairs shortest path problem


Given a input Graph “G={V,E}”, the shortest
path is calculated between every pair of
vertices in G

62

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Bellman – Ford Algorithm
Key points to be remembered
Coined by “Richard Bellman and Lester Ford”

Example of “Single source shortest path


problem”

It is an algorithm that computes shortest paths


from a single source vertex to all of the other
vertices in a weighted digraph.

It is slower than Dijkstra's algorithm for the


same problem, but more versatile

Bellman – Ford Algorithm


Key points to be remembered
This algorithm will be applicable to the graph
which has negative edge weights [i.e.,
negative cycle]

Algorithm takes |v|-1 iterations.

63

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Bellman – Ford Algorithm
Problem 1: Find Shortest path using Bellman
Ford algorithm? [Use vertex ‘A’ as source]
1
A B

5
2 3
2
7
S T
10
-2
3
C D

Bellman – Ford Algorithm


Solution: Find Shortest path using Bellman Ford
algorithm? [Use vertex ‘A’ as source]
1
A B

5
2 3
Graph has 6 vertices
2
7
S T
10
-2
3
C D
Algorithm has 5 iterations

64

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Bellman – Ford Algorithm
Solution:

Initial stage: Shortest cost:


Set all d(v) = if(d(v) > d(u)+w(u,v))
d(S) =0 update the cost & Pi(v)

S A B C D T
Shortest
0
Distance d(v)
Predecessor
Vertex pi(v)

S A B C D T
Shortest
0 5 -2
Distance d(v)
Predecessor
S S
Vertex pi(v)

Iteration 1: Start the process from source vertex


Find Shortest cost:
S = adj{A, C} if(d(v) > d(u)+w(u,v))
u v update the cost & Pi(v)
S A
> 0+5
True;
d(A) = 5 from “S”
u v
S C > 0-2
True;
d(C) = -2 from “S”

65

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
S A B C D T
Shortest
0 5 6 -2
Distance d(v)
Predecessor
S A S
Vertex pi(v)

Iteration 1: Select Vertex “A”

A = adj{B}
u v > 5+1
A B True;
d(B) = 6 from “A”

S A B C D T
Shortest
0 5 6 -2 13 9
Distance d(v)
Predecessor
S A S B B
Vertex pi(v)

Iteration 1: Select Vertex “B” B = adj{C, D, T}

u v -2 > 6+2
B C False; Don’t update d(C)
d(C) = -2 from “A”
u v > 6+7
B D true; update d(D)
d(D) = 13 from “B”
u v > 6+3
B T true; update d(T)
d(T) = 9 from “B”

66

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
S A B C D T
Shortest
0 50 6 -2 9
Distance d(v) 113
Predecessor
SC A S BC B
Vertex pi(v)

Iteration 1: Select Vertex “C” C = adj{A, D}

u v 5 > -2+2
C A True; update d(A)
d(A) = 0 from “C”

u v 13 > -2+3
C D true; update d(D)
d(D) = 1 from “C”

S A B C D T
Shortest
0 50 6 -2 9
Distance d(v) 113
Predecessor
SC A S BC B
Vertex pi(v)

Iteration 1: Select Vertex “D” D = adj{T}

u v 9 > 1+10
D T False; Don’t update d(T)
d(T) = 9 from “B”

Iteration 1 is over

67

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
S A B C D T
Shortest
0 0 6 -2 1 9
Distance d(v)
Predecessor
C A S C B
Vertex pi(v)

Iteration 2: Repeat from “S” So Select Vertex “S”

S = adj{A, C}
u v
0 > 0+5
S A
False;
d(A) = 0 from “C”
u v
S C -2 > 0-2
Same;
d(C) = -2 from “S”

S A B C D T
Shortest
0 0 61 -2 1 9
Distance d(v)
Predecessor
C A S C B
Vertex pi(v)

Iteration 2: Select Vertex “A”

A = adj{B}
u v
6 > 0+1
A B
True;
d(B) = 1 from “A”

68

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
S A B C D T
Shortest
0 0 61 -2 1 94
Distance d(v)
Predecessor
C A S C B
Vertex pi(v)

Iteration 2: Select Vertex “B” B = adj{C, D, T}

u v -2 > 1+2
B C False; Don’t update d(C)
d(C) = -2 from “S”
u v 1 > 1+7
B D false; don’t update d(D)
d(D) = 1 from “C”
u v 9 > 1+3
B T true; update d(T)
d(T) = 4 from “B”

S A B C D T
Shortest
0 0 1 -2 1 4
Distance d(v)
Predecessor
C A S C B
Vertex pi(v)

Iteration 2: Select Vertex “C” C = adj{A, D}

u v 0 > -2+2
C A same; Don’t update d(A)
d(A) = 0 from “C”

u v 1 > -2+3
C D same; don’t update d(D)
d(D) = 1 from “C”

69

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
S A B C D T
Shortest
0 0 1 -2 1 4
Distance d(v)
Predecessor
C A S C B
Vertex pi(v)

Iteration 2: Select Vertex “D” D = adj{T}

u v 4 > 1+10
D T false; Don’t update d(T)
d(T) = 4 from “B”

Upto Iteration 5

S A B C D T
Shortest 0 1 -2
0 1 4
Distance d(v)
Predecessor C A S C B
Vertex pi(v)

Shortest cost path from source vertex


1
A B

3
2
S T

-2
3
C D

70

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Bellman – Ford Algorithm
Problem 2: Find Shortest path using Bellman
Ford algorithm? [Use vertex ‘1’ as source]

Connected Components
Key points to be remembered
A graph is said to be connected if for every pair
of its vertices u and V there is a path from u to V

A connected component is the maximal


subgraph of a given graph

Sub graph
A sub graph of a given graph G=(V,E) is a
graph G’=(V’,E’) such that V’ V and E’ E

71

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Connected Components
Key points to be remembered

A B C A B

C D E C D

Example: Connected Components

Connected Components
Key points to be remembered
A
G F

B C E
H I

Example: Not Connected Components cos’ there is no path from A to F

72

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Connected Components
Identifying connected components using BFS
BFS can be used to determine whether G is
connected or not

Using BFS, all newly visited vertices are put on to


the list

Sub-graph of the given graph is formed by the


vertices on this list will make up a connected
component.

BFS can be obtained by using reflexive transitive


closure matrix of a undirected graph

Connected Components
Identifying connected components using BFS
A* is the reflexive transitive closure matrix of a
undirected graph

A*(i,j)=1 is determined by connect[i]=connect[j]

The graph G is a connected iff it forms a


spanning tree “t”

73

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Connected Components
Example for connected component using
Spanning tree
Find whether the following graph is connected
0

1 2

3 4 5 6

Connected Components
Solution 1(a): Finding connected component using
BFS
Process starts at initial vertex 0, Spanning tree
is empty; t={0}
As per the ideal of BFS, algorithm visits 0 to 1,
now spanning tree, t={(0,1)}
It visits vertex 2, t={(0,1),(0,2)}
Next visits vertex 3, t={(0,1),(0,2),(1,3)}
Next visits vertex 4, t={(0,1),(0,2),(1,3),(1,4)}
Next visits vertex 5, t={(0,1),(0,2),(1,3),(1,4),(2,5)}
Next visits vertex 6, t={(0,1),(0,2),(1,3),(1,4),(2,5)
,(2,6)}

74

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Connected Components
Solution: Finding connected component using BFS
Next visits vertex 7, t={(0,1),(0,2),(1,3),(1,4),(2,5)
,(2,6),(3,7)}
0
Spanning tree of the graph
Using BFS
1 2

3 4 5 6

Connected Components
Solution 1(a): Finding connected component using
DFS
Process starts at initial vertex 0, Spanning tree
is empty; t={0}
As per the idea of DFS, algorithm visits 0 to 1,
now spanning tree, t={(0,1)}
It visits vertex 3, t={(0,1),(1,3)}
Next visits vertex 7, t={(0,1),(1,3),(3,7)}
Next visits vertex 4, t={(0,1),(1,3),(3,7),(7,4)}
Next visits vertex 5, t={(0,1),(1,3),(3,7),(7,4),(7,5)}
Next visits vertex 2,
t={(0,1),(1,3),(3,7),(7,4),(7,5),(5,2)}

75

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Connected Components
Solution: Finding connected component using BFS
Next visits vertex 6,
t={(0,1),(1,3),(3,7),(7,4),(7,5),(5,2),(2,6)}
0
Spanning tree of the graph
Using DFS
1 2

3 4 5 6

Connected Components
Complexity of connected Graph
Space Complexity
Array = n locations
Queue = (n-1) locations
Edges = (n-1) locations
Remaining variables = 2
Total space needed = 3 n locations

Time Complexity
needs O(n+e) for n vertices and e edges of a graph G

76

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Biconnected Components
Key points to be remembered
A graph is said to be bi-connected iff if it
contains no articulation point in a graph

Articulation Point
A vertex V in a connected graph G is an
articulation point iff if the deletion of vertex V
together with all the edges incident to V
disconnects the graph into 2 or more non-
empty components

Biconnected Components
Example-1 for Articulation Point in a graph
6

From this graph, it is found that


1 5
Vertex 2 is an articulation point

4 2 7 Deletion of this vertex produces


2 disconnected non-empty
components
3 8

10 9

77

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Biconnected Components
Example-1 for Articulation Point in a graph

1 6
After deleting vertex 2
4 5

7
3

10 9 8

Biconnected Components
Example-2 for Articulation Point in a graph

From this graph, it is found that


1
there is no articulation point

4 2 Deletion of any vertex does not


produces 2 disconnected non-empty
components
3

5 4

78

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Biconnected Components
Methods to find Articulation Point
Common vertex in Biconnected component
Depth first spanning tree
Lowest depth first number L(u)

3 ways

Biconnected Components
Methods 1: finding Articulation Point using
common vertex in Biconnected component
2 biconnected component can have at most one
vertex in common and this vertex is referred as
“Articulation Point”

If G has P articulation points and b biconnected


components then the graph contains (b-p) new
edges in G

79

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Biconnected Components
Methods 1: finding Articulation Point using
common vertex in Biconnected component
1
6
5
4 2
5
2 7
3

8
3 3

10 9 Biconnected Components of Graph G

Biconnected Components
Methods 1: finding Articulation Point using
common vertex in Biconnected component
From the biconnected components, it is found
that a graph may have vertex 2 is an articulation
point

Combining all biconnected components via


vertex-2, it requires addition (5-2) of 3 edges

80

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Biconnected Components
Methods 1: finding Articulation Point using
common vertex in Biconnected component
6

1 5
Result of connecting
4 2 7 biconnected components

3 8

10 9

Branch & Bound Technique


Key points to be remembered
“Branch and Bound” is an algorithm design
technique that enhances the idea of generating
a State Space Tree with the idea of estimating
the best value obtainable from the current node
of the decision tree.

If such an estimate is not superior to the best


solution seen up to that point in the processing,
the node is eliminated from further
consideration

81

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Branch & Bound Technique
Key points to be remembered
This idea can be strengthened if we deal with
optimization problem where these problems
are associated with 2 terms:

1. Feasible solution
2. Optimal Solution

Branch & Bound Technique


Key points to be remembered
Feasible Solution
It is a point in the problem space that
satisfies all the problem constraints

For Ex.:
Hamiltonian Circuit in the TSP Problem
Subset of items whose weight does not
exceeds the knapsack capacity

82

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Branch & Bound Technique
Key points to be remembered
Optimal Solution
It is a feasible solution with the best value
that maximizes the objective of the given
function

For Ex.:
Shortest Hamiltonian Circuit
Most valuable subset of items that fits
with the knapsack capacity

Branch & Bound Technique


Basic terminology to be remembered
Live Node
It is a node that has been generated but
whose children have not been generated

E- Node
It is a live node whose children are currently
being explored. In other words, an E-node is
a node currently being explored

83

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Branch & Bound Technique
Basic terminology to be remembered
Dead Node
It is a node that is not to be expanded or
explored further. All children of a dead node
have already been explored

Branch & Bound Technique

A B

C D

84

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]
Branch & Bound Technique

A B

Branch & Bound Technique

A B

E D

85

Dr.A.Thomas Paul Roy, Professor, CSE Department, PSNACET, Dindigul. Email: [email protected]

You might also like