Prims and Kruskal's Algorithm Problem
Prims and Kruskal's Algorithm Problem
SPANNING TREE
G(V, E) be a
Let G
Let =
12.12.55 8.3
5
2
e
o d
minimum
weight is 4.8.
6.3
b
4.8
od
e
GRAPH THEORY (BE. IVSEM.
(3) Now there is one vertex incident with e i.e. (e, t) and
one vertex
incident with c i.e. (C, b).
We, f 5, W (c, b) 6.3. =
Hence minimum
weight is 5.
bo
aa
(4) nere Is one vertex incident with c i.c. (C, b)
two vertices incident with fi.e. (f, a) (f. b).
12.5. Hence
(f, a)
-
W(C, b) =
6.3, w (F. b) =
8.3, w
bo
fo-
bo
2 3
Soln.
Let us select vertex b as edge (b, e) has minimum
(1)
weight.
c)and w (b, c)
=
7.
4, w (e, c)
=
w (e, d)
=
b
5-39 DIS, MAT
NOw there is one
edge incident with B
b i.c. isedge incident
dge incident with a i.c. (a, d) and (b, c) and one (2) Now there one
incident with E
with e i.e. (e, c), (e, d). two edges incident i.e. (B, A) and two cdges
(b. c) 6, w (a, d)= 5, w i.c. (E, D). (E, H)
(e, c) =
7, 5,
Hence minimum weight is4 w (e, d) 4
minimum weight is 5.
d Hence
B
bo
E
(4)
Now only one vertex c is left
which is
incident with
vertices b, e, d w(b, c) = 6, w (e. c) 7, w (d,
=
H
Hence minimum weight is 3. c)3.
(3) Now there is one edge incident with B i.e. (B, A) and
15 G 15 D E
Soln. Fo- sG H
(1) Let us select vertex B as edge (B, E) has minimum
(6) Now there is one edge incident with F i.e.
(F, C) and
weight. one edge incident with G i.e. (G, C) and one edge
B incident with B i.e. (B, A) and
w(F, C) 15, =
Hence minimum
weight is 5.
A B
H
This is the
required minimal spanning tree.
Minimal cost =3 +5 +5 +4+ 15+ 15 +5 52
Ex.32. Using Prim's algorithm find the minimal
tree for the
spanning
following graph using 'a' as the root.
CSYCT/CE:S-06,12,13, W-12, IT:S-08,09,13
Soln.
1) Let us select vertex a. There are two
edges incident
with a i.e. (a, d), (a, c). since the
weight are not given,
let us select edge (a, c).
been.
weighted graph using Kruskal's algorith
Example (28): Find a minimal spanning tree for a h
15
13
16
14 12 1A
16
14
15
Solution: We will find a minimal spanning tree for a weighted graph using Kruska>'s algorithm is as
follows
Edge (1,2) 3,4) (1,8) (4,5) (2.7) (3,6) (7,8) (5,6) (58) (67) (14) (2.3)
Weight 12 12 13 1311 1411 | 14 14 14 15 |15 16 16
G r a p l l
15
12 12
14 14
Example (29): Determine a railway network of minimal cost for cities in the following figure.
A 15 B
15 3
D 5
c 18 5
E
15
H
15 15 Kruska>'s
the network. Using
A minimal spanning tree is the minimum cost of constructing
Solution:
tree as follows:
w e get the minimal spanning GF)
algorithm CE)A,B)(A,D)(EF(F.H) (GH)
(BC)(D.F)(AG (CD) 15 18
Edge 511 5 15 15 15 15
4 5
Weight 3
15
3
5
3 + 5 + 4 + 5 + 5 + 1 5 + 1 5 - 5 2
4
9
Solution: We will finda minimal spanning tree for a weighted graph using Kruskal's algorithm as follo.ws:
2
1 d
b
3
e
Fig. 14.14
into a Table 14..
SOlution. We collect the edges with their weights
edge weight
1:
(b, c)
1
(c, e)
(c, d)
(a, b) 3
(e, d) 3
(a, d)
(b, e) 4
Table 14.1
b.
d
nning
Example8.3 Show how Kruskal's
spanning
algorithm finds a minimal
spanning tree of the graph of Fig
14.15. a
9
d 6
e
11 10
3
Fig. 14.15
the edges with their weights into table
Solution. We collect
a
edge weight
, c)
(b, d)
(e, g) 3
(b, e)
(d, g)
(d e)
(d, c)
(a, d) 8
(a, b) 9
10
d. f)
11
(c,f)
14
Table 14.22
below.
tree are shown
The steps of finding a minimal spanning
has minimal weight
1. Choose the edge (ac) as it a
2 Add the next edge (c. d)
MATIC
nEMATIO
a
d
3. Add the edge (d, b)
d
4. Add the edge (b, e)
a
b
g
6. Add the edge (d, D
a
e
d
9
Since vertices are 7 and we have chosen 6 edges, we stop the algorithm and the minimal
spanning tree is produced.