Download presentation
Presentation is loading. Please wait.
1
CSC 172 DATA STRUCTURES
2
Kruskal’s Algorithm An example of a “greedy” algorithm
“do what seems best at the moment” Use the merge/find MWST algorithm on the edges in ascending order O(m log m) Since m <= n2, log m <= 2 log n, so O(m log n) time
3
Find the MWST A 10 1 F B 8 7 9 5 2 6 11 12 E C 3 4 D
4
Find the MWST 1 + 2 + 3 + 4 + 5 == 15 A 10 1 F B 8 7 9 5 2 6 11 12 E C
== 15 A 10 1 F B 8 7 9 5 2 6 11 12 E C 3 4 D
5
GREED IS NOT ALWAYS GOOD
6
Find the minimum cycle A 10 1 F B 8 7 9 5 2 6 11 12 E C 3 4 D
7
Find the minimum cycle 1 + 2 + 3 + 4 + 5 +10 == 25 A 10 1 F B 8 7 9 5
6 11 12 E C 3 4 D
8
Find the minimum cycle 1 + 2 + 3 + 6 + 5 + 7 = 24 A 10 1 F B 8 7 9 5 2
11 12 E C 3 4 D
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.