Upload
olivia-burns
View
212
Download
0
Embed Size (px)
Citation preview
Prim’s Algorithm from a matrix
A cable TV company is installing a system of cables to connect all the towns in the region. The numbers in the network are distances in miles.
A
D
CB
E
F
10
812 15
12
20
13
19
14
Prim’s Algorithm from a matrix
Show this graph in matrix form
A
D
CB
E
F
10
812 15
12
20
13
19
14
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
A dash (-) in the table means that there is no direct connection between these vertices.
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
1. Choose a starting vertex say A. Delete row A and label column A with 1. Look for the smallest entry in column A
1
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
2. Label column B with a 2. Delete row B. Now choose the smallest uncovered value from columns A or B
1 2
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
3. Label column D with a 3. Delete row D. Now choose the smallest uncovered value from columns A or B or D
1 2 3
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
4. Label column E with a 4. Delete row E. Now choose the smallest uncovered value from columns A or B or D or E
1 2 3 4
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
5. Label column C with a 5. Delete row C. Now choose the smallest uncovered value from columns A, B, D, E, or C
1 2 3 45
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
5. Label column F with a 6. We now have connected all the vertices into the spanning tree.
1 2 3 45 6
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
Length of the cabling = 8 + 10 + 12 + 13 + 19 = 62 miles
1 2 3 45 6
Prim’s Algorithm from a matrix
A B C D E FA - 8 - 10 - -B 8 - 14 12 - -C - 14 - 15 13 -D 10 12 15 - 12 20E - - 13 12 - 19F - - - 20 19 -
Length of the cabling = 8 + 10 + 12 + 13 + 19 = 62 miles
1 2 3 45 6
AB
D
C
E
F
8
10
12
13
19