11
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 C B E F 1 0 8 12 1 5 12 2 0 1 3 19 14

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

Embed Size (px)

Citation preview

Page 1: 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

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

Page 2: 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

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

Page 3: 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

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.

Page 4: 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

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

Page 5: 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

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

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

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

Page 10: 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

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

Page 11: 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

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