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

Prims and Kruskal's Algorithm Problem

This document provides algorithms to find the minimum spanning tree of a connected weighted graph. It describes Prim's algorithm and Kruskal's algorithm in 3 steps each. It then provides an example of applying Prim's algorithm to find the minimum spanning tree of a graph with 5 vertices and 7 edges, with a total weight of 30.6.

Uploaded by

Gunjan
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)
421 views

Prims and Kruskal's Algorithm Problem

This document provides algorithms to find the minimum spanning tree of a connected weighted graph. It describes Prim's algorithm and Kruskal's algorithm in 3 steps each. It then provides an example of applying Prim's algorithm to find the minimum spanning tree of a graph with 5 vertices and 7 edges, with a total weight of 30.6.

Uploaded by

Gunjan
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/ 13

MINIMAL

SPANNING TREE
G(V, E) be a
Let G
Let =

connected CS/CT/CE: S-11


weight of aa spanning tree of weighted graph. The
weight
weights of the edges. A G is the sum
of the
minimal spanning tree ofG is
a
spanning tree of G with
Prim's Algorithm to findminimum weight.
Input: A connected minimal spanning tree:
Output: A minimal weighted graph G.
spanning tree T.
step (1) : Select an
edge in G with minimum
select any vertex of this weight and
incident with the selected edge. Among all the edges
mimimum weight. Include vertex,
it in T.
select an edge with
Step (2): At each stage, select
an edge
weight with minimum
joining
a vertex already included in T and a
vertex which is yet to be
included. (Make sure that a
circuit is not formed). Include it in T.
Step (3) : Repeat this process until all the vertices of G are
included in T.
Kruskal's Algorithm:
This algorithm provides an acylic subgraph T of a
connected weighted graph G which is a minimal
spanning tree of G. The algorithm involves the
following steps
Input: A connected weighted graph G.
Output : A minimal spanning tree T.
Step 1: List all the edges (which do not form a loop) of G in
non-decreasing order of their weights.
Step 2 : Select
edge of minimum weight (If more than
an
one edge of minimum
weight, arbitrarily choose one of
them). This the first edge of T.
Step 3 At each stage, select an
:
edge of minimum weight
from all the remaining edges
of G if it does not forma
circuit with the previously selected in T. add the
edges
edge to T.
Step 4 : Repeat step 3 until n -

1 edges have been selected,


when is the number of vertices in G. The
n
followingg
examples illustrate these steps.
Ex.29. Find the minimal
spanning tree of
b
6.3
4.8
a o

12.12.55 8.3

5
2

e
o d

Using Prim's algorithm.


Soln.
(1) Let us select vertex e as the edge (e, c) has
weight. minimum

2) Now there are two


edges incident with c i.e. (c, d), (c,
b) and w (c, d) 4.8, w (c, b) 6.3. Hence
=
=

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

minimum weight is 6.3.

bo

fo-

(5) Now only one vertex a incident with fis left.

bo

This is the required minimal spanning tree.


lts weight -2 +4.8+ 5+6.3 + 12.5 =30.6.

Ex.30. Using Prim's algorithm find the minimal spanning


tree of CS/CTICE: W-07, S-11,12
IT: W-12

2 3

Soln.
Let us select vertex b as edge (b, e) has minimum
(1)
weight.

are two edges incident with b i.e. (b, c), (b.


(2) Now there
incident with e ie. (e, a), (e, d), (e,
a) and three edges
6, w (6, a)
=
2, w (e, a) 2.
=

c)and w (b, c)
=

7.
4, w (e, c)
=

w (e, d)
=

Hence minimum weight is 2.


a a

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

w (B, A)= 15, w(E, D)


w (E, H) = 5

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

d one edge incident with E


i.c. (E, D) and one edge incident with H i.e. (H, G)
w(B, A) 15, w (E, D) = 5, w (H, G) = 15.

Hence minimum weight is 5.


5) This is the required minimal
(lts weight = 10)
spanning trec. B

If we would have gone for


edge (b, a) in step (2) Do E
instead of edge (e, a) then the
spanning tree would
have been
H
(4) Now there is one edge incident with B i.e. (B, A) and
d ne edge incident with D i.c. (D, G) and one edge
incident with H
i.e. (H, G) and w (D, G) = 4,
w (B, A) = 15, w (H, G) = 15.

This would not have been Hence minimum weight is 4.


a minimal spanning tree
because ist weight is 11.

Ex.31. Determine a railway network of minimal cost for D


the following cities.
CS/CT/CE: W-09,10 G H
IT: S-07 (5) Now there is one edge incident with B i.e
(B, A) and
15 incident with G i.e. (G, F), (G, C)
two edges
15 w (B, A) 15, w (G, F)= 15, w (G, C) = 18.
3 Hence minimum weight is 15.
D 5
c 18
E
B
15 5

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, =

w(G, C)= 18, w (B, A) 15. =

Hence minimum weight is 15.


E
5-40
B
C
D
G H
(7) Now only one vertex A is left which is
and C. incident with B
w
(B, A)= 15, w (C, A) 5. =

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

(2) Now there is only one


edge incident with i.e.
(a, d)
a
and one edge incident with c i.e.
(c, b). Since the
weight are not given let us select edge (c, b).

(3) Now only one vertex d is left which is incident with a


and b ie (a, d), (b, d). Since the
weights are not given
let us select edge (a, d).
tree.
This is therequired minimal spanning
selected edge
In the above step (3), if we would have
would have
(6. d). then the minimal spanning tree

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

The minimunum weight is 12+12+13+13+14+14+15-93

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

The minimum weight is network is 52.


the
minimum cost for constructing
Hence

find a minimal spanning tree for following weighted graph


Kruskal's algorithm,
Example (30): Using
Dry

4
9

Solution: We will finda minimal spanning tree for a weighted graph using Kruskal's algorithm as follo.ws:

Edge (B,D)(A,E) (D.F) (B.F) (CE) (A,C) (B,E) (B,C) (A,F)


Weight 3 40 40 5 6 7 7

The minimum weight is 3+4+4+6+7-24


Example 7. Show how Kruskal's algorithm find a minimal spanning tree tor the
the graph
14.14.
graph of oFi

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

tree are shown below


The steps of finding a minimal spanning
a minimal weight.
1. Choose the edge (b, c) as it has
b C

2. Add the next edge (c, e)


b

3 Add the edge (c, d)


b d
T R E E

edge (b, a) 479


Add the

b.
d

Since vertie ties are 5 and we have


choosen 4
Is
produced
edges, we stop the algorithm and the minimal
tree

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

5. Add the edge (e, 8)

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy