DS Lecture17
DS Lecture17
b c
a d
e
f
For economic reasons, it is desired to construct the least possible number of
roads to connect the six cities.
One such set of roads is
b c
a
e d
Note that the subgraph representing these roads is a tree, it is connected &
circuit-free (six vertices and five edges) 1
SPANNING TREE
b c
a d
e
f
SOLUTION
The graph has 6 vertices & 9 edges so we must delete 9 - 6 + 1 = 4 edges.
We delete an edge in each cycle. b c
v0 v1
v3 v2
SOLUTION
The graph has n = 4 vertices and e = 5 edges. So we must delete
e-v+1=5-4+1=2
edges from the cycles in the graph to obtain a spanning tree.
v0 v1
v3 v2
(2) Delete v0v1 & v1v3 to get
v0 v1
3
v3 v2
Original Graph
v0 v1
v3 v2
(3) Delete v0v1 & v2v3 to get
v0 v1
v3 v2
v0 v1
v3 v2
4
Original Graph
v0 v1
v3 v2
v0 v1
v3 v2
v0 v1
v3 v2
5
Original Graph
v0 v1
v3 v2
v0 v1
v3 v2
v0 v1
v3 v2
6
EXERCISE
Clearly the graph itself is a tree (six vertices and five edges). Hence the
graph is itself a spanning tree.
c d
Now
Number of vertices = n = 4 and number of edges = e = 6
Hence we must remove
e-v+1=6-4+1=3
edges to obtain a spanning tree.
7
Let ab, bd & cd edges are removed. The associated spanning tree is
a b
c d
KIRCHHOFF’S THEOREM
OR MATRIX - TREE THEOREM
EXAMPLE
a b c
8
a b c
d
SOLUTION
We will use the Kirchoff`s Theorem for which first
we will calculate the adjacency matrix of G is
a b c d
a 0 1 0 1
b 1 0 1 1
A(G )
c 0 1 0 1
d 1 1 1 0
9
Now cofactor of the element at (1,1) in M is
3 1 1
1 2 1
1 1 3
2 1 1 1 1 2
3 (1) (1)
1 3 1 3 1 1
3(6 1) (3 1) (1)(1 2)
15 4 3
8
Hence there will be 8 Spanning trees for the given graph. You can also find
out the number of spanning trees of the example for which we find the
spanning trees and you will see that these are also 8 as we counted them.
EXERCISE
How many non-isomorphic spanning trees does the following simple graph
has?
10
SOLUTION There are eight spanning tree of the graph
1 2 3 4
5 6 7 8
Clearly 1 & 6 are isomorphic, and 2,3,4,5,7,8 are isomorphic. Hence there
are only two non-isomorphic spanning trees of the given graph.
EXERCISE
11
f e d
Because the construction of a pipeline is very expensive, construct as few
pipelines as possible.
(The company does not mind if oil has to be routed through one or more
intermediate facilities)
SOLUTION
The task is to find a set of edges which together with the incident vertices
from a connected graph containing all the vertices and having no cycles.
This will allow oil to go from any storage facility to any other without
unnecessary building costs. Thus, a tree containing all the vertices of the
graph is to be soughed. One selection of edges is
a b c
f e d
DEFINITION
A weighted graph is a graph for which each edge has an associated real
number weight.
The sum of the weights of all the edges is the total weight of the graph.
12
EXAMPLE
The figure shows a weighted graph with total weight
2 + 6 + 3 + 2 + 3 + 1 = 17
2 6
2 1
A minimal spanning tree for a weighted graph is a spanning tree that has the
least possible total weight compared to all other spanning trees of the graph.
If G is a weighted graph and e is an edge of G then w(e) denotes the weight
of e and w(G) denotes the total weight of G.
EXERCISE
Find the three spanning trees of the weighted graph below. Also indicate the
minimal spanning tree.
2 6
2 1
13
3
SOLUTION
6
2 w(T1)=14
2 1
2 2 1
w(T2)=11
3
T3
2 6 1 w(T3)=15
T2 is the minimal spanning tree, since it has the minimum weight among the
spanning trees.
14
KRUSKAL’S ALGORITHM
Use Kruskal’s algorithm to find a minimal spanning tree for the graph
below. Indicate the order in which edges are added to form the tree.
b 7 c
1 4
8 e
a 10 d
9 3
2
5
g 6 f
SOLUTION
Minimal spanning tree:
b c
7
1 4
e 3
a d
2
g 6 f
b 7 c
1 4
8 e
10 d
a
3
9
2
5
g 6 f
SOLUTION:
Minimal spanning tree
b c
7
1 4
e 3
a d
2
g 6 f
a 9 b
6
8 c 7
3 5
d 5 e
SOLUTION
(a) When Kruskal’s algorithm is applied, edges are added in one of
the following two orders:
c c
18
d e d e
a 9 b
6
8 c 7
3 5
d 5 e
b a b
a
c c
d e d e
19