Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prim’s algorithm for minimum spanning trees

Similar presentations


Presentation on theme: "Prim’s algorithm for minimum spanning trees"— Presentation transcript:

1 Prim’s algorithm for minimum spanning trees

2 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

3 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

4 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

5 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

6 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

7 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

8 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

9 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

10 Kruskal’s algorithm for minimum spanning trees

11 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 3 7 8

12 1 9 2 8 4 6 1 4 3 4 5 5 1 9 7 11 2 6 3 5 7 8 2

13 1 9 2 8 4 6 1 4 3 4 5 5 1 9 7 11 2 6 3 5 7 8 6 2

14 1 9 2 8 4 6 1 4 3 4 5 5 1 9 7 11 2 6 3 5 7 8 8 6 2

15 1 9 2 8 1 4 6 4 3 4 5 5 1 9 7 11 2 6 7 3 5 7 8 1 8 6 2

16 4 1 9 2 8 4 6 1 4 3 4 3 5 5 1 9 7 11 2 6 7 3 5 7 8 1 8 6 2

17 4 1 9 2 8 4 6 1 4 3 4 3 5 5 1 9 7 11 2 6 7 3 5 7 8 1 8 6 2

18 4 1 9 2 8 4 6 1 4 3 4 3 5 5 1 9 7 11 2 6 7 3 5 7 8 1 8 6 2

19 Dijkstra’s algorithm for single-source shortest paths

20 x 4 s 5 6 1 k z 1 3 b 5 c u 4 1 5 2 4 d 2 y 3 V’ = { s} Choose node b

21 V’ = { s, b} x s k b c u d Choose node c z y 4 5 6 1 1 3 5 4 1 5 2 4 2

22 V’ = { s, b, c} x s k b c u d Choose node d z y 4 5 6 1 1 3 5 4 1 5 2

23 V’ = { s, b, c, d} x s k b c u d Choose node y z y 4 5 6 1 1 3 5 4 1 5
2 4 d 2 y 3 V’ = { s, b, c, d} Choose node y

24 x 4 s 5 6 1 k z 1 3 b 5 c u 4 1 5 2 4 d 2 y 3 V’ = { s, b, c, d, y} Whenever a new node is added to V’, we need to update nearest(x) for all x not in V’.


Download ppt "Prim’s algorithm for minimum spanning trees"

Similar presentations


Ads by Google