Algorithms R OBERT S EDGEWICK | K EVIN W AYNE K RUSKAL ' S A LGORITHM D EMO Algorithms F O U R T H E D I T I O N R OBERT S EDGEWICK | K EVIN W AYNE http://algs4.cs.princeton.edu
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. graph edges sorted by weight 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 an edge-weighted graph 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93 2
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. in MST 0-7 0.16 1 3 5 7 2 0 6 4 does not create a cycle 3
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. does not create a cycle 0-7 0.16 in MST 2-3 0.17 1 3 5 7 2 0 6 4 4
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. does not create a cycle 0-7 0.16 2-3 0.17 1 in MST 1-7 0.19 3 5 7 2 0 6 4 5
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 in MST 0-2 0.26 5 7 2 0 6 4 does not create a cycle 6
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 in MST 7 2 0 6 4 does not create a cycle 7
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. creates a cycle 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 not in MST 2 0 6 4 8
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. creates a cycle 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 not in MST 0 6 4 9
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. creates a cycle 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 not in MST 2-7 0.34 6 4 10
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 in MST 4-5 0.35 6 4 does not create a cycle 11
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. creates a cycle 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 not in MST 1-2 0.36 6 4 12
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 not in 4 MST 4-7 0.37 creates a cycle 13
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 not in MST creates a cycle 14
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 does not create a cycle 6-2 0.40 in MST 15
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 creates a cycle 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 6-2 0.40 not in MST 3-6 0.52 16
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 creates a cycle 6-2 0.40 3-6 0.52 6-0 0.58 not in MST 17
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 creates a cycle 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93 not in MST 18
Kruskal's algorithm demo Consider edges in ascending order of weight. ・ Add next edge to tree T unless doing so would create a cycle. 0-7 0.16 2-3 0.17 1 1-7 0.19 3 0-2 0.26 5 5-7 0.28 7 1-3 0.29 2 1-5 0.32 0 2-7 0.34 4-5 0.35 1-2 0.36 6 4 4-7 0.37 0-4 0.38 a minimum spanning tree 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93 19
Recommend
More recommend