0% found this document useful (0 votes)
741 views10 pages

D1, L5 Prim's Algorithm From A Table

Prim's algorithm is used to find the minimum spanning tree of a connected, undirected graph. It works by starting with one vertex and successively adding edges to form a tree that includes all vertices. The algorithm selects the shortest edge that connects a chosen vertex to an unconnected vertex until all vertices are included. When applied to connect five villages to a market town, Prim's algorithm produced a minimum spanning tree with a total cable length of 18km.

Uploaded by

mokhtarppg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
741 views10 pages

D1, L5 Prim's Algorithm From A Table

Prim's algorithm is used to find the minimum spanning tree of a connected, undirected graph. It works by starting with one vertex and successively adding edges to form a tree that includes all vertices. The algorithm selects the shortest edge that connects a chosen vertex to an unconnected vertex until all vertices are included. When applied to connect five villages to a market town, Prim's algorithm produced a minimum spanning tree with a total cable length of 18km.

Uploaded by

mokhtarppg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Minimum Spanning tree

Prims algorithm

1.

Select any vertex

2.

Select the shortest edge connected to that vertex

3.

Select the shortest edge which connects a previously chosen


vertex to a new vertex

4.

Repeat step 3 until all vertices have been connected

Example
A cable company want to connect five villages to their network
which currently extends to the market town of Avenford. What is the
minimum length of cable needed?

Brinleigh

Cornwell

Avenford

7
4

Fingley

5
2
Edan

Donster

Prims algorithm in tabular form


First put the information from the network into a distance matrix

A
B
C
D
E
F

A
3
4
7

B
3
5
8

C
5
4
6

D
4
2
8

E
4
2
5

F
7
8
6
8
5
-

Start at vertex A. Label column A 1 .


Delete row A
Select the smallest entry in column A (AB, length 3)

Brinleigh

3
Avenford

A
B
C
D
E
F

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

Label column B 2
Delete row B
Select the smallest uncovered entry in either column
A or column B (AE, length 4)

Brinleigh

3
Avenford

4
Edan

A
B
C
D
E
F

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

Label column E 3
Delete row E
Select the smallest uncovered entry in either
column A, B or E (ED, length 2)

Brinleigh

A
B
C
D
E
F

Avenford
Donster

2
Edan

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

Label column D 4
Delete row D
Select the smallest uncovered entry in either
column A, B, D or E (DC, length 4)

Cornwell

Brinleigh

A
B
C
D
E
F

Avenford
Donster

2
Edan

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

Label column C 5
Delete row C
Select the smallest uncovered entry in either
column A, B, D, E or C (EF, length 5)

Cornwell

Brinleigh

4
Fingley

A
B
C
D
E
F

Avenford
Donster

5
4

2
Edan

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

FINALLY
Label column F 6
Delete row F

Cornwell

Brinleigh

4
Fingley

A
B
C
D
E
F

Avenford
Donster

5
4

2
Edan

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

FINALLY
Label column F 6
Delete row F

Cornwell

Brinleigh

4
Fingley

A
B
C
D
E
F

A
3
4
7

B
3
5
8

C D
- 5 - 4
4 - 2
6 8

E
4
2
5

F
7
8
6
8
5
-

Avenford
Donster

5
4

2
Edan

The spanning tree is shown in the diagram


Length 3 + 4 + 4 + 2 + 5 = 18Km

You might also like