ROBERT SEDGEWICK | KEVIN WAYNE
F O U R T H E D I T I O N
Algorithms
http://algs4.cs.princeton.edu
Algorithms
ROBERT SEDGEWICK | KEVIN WAYNE
Algorithms R OBERT S EDGEWICK | K EVIN W AYNE K RUSKAL ' S A LGORITHM - - PowerPoint PPT Presentation
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
ROBERT SEDGEWICK | KEVIN WAYNE
F O U R T H E D I T I O N
http://algs4.cs.princeton.edu
ROBERT SEDGEWICK | KEVIN WAYNE
Consider edges in ascending order of weight.
2
5 4 7 1 3 2 6 0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93
graph edges sorted by weight
an edge-weighted graph
Consider edges in ascending order of weight.
3
0-7 0.16 5 4 7 1 3 2 6
does not create a cycle in MST
Consider edges in ascending order of weight.
4
0-7 0.16 2-3 0.17 5 4 7 1 3 2 6
in MST does not create a cycle
Consider edges in ascending order of weight.
5
0-7 0.16 2-3 0.17 1-7 0.19 5 4 7 1 3 2 6
in MST does not create a cycle
Consider edges in ascending order of weight.
6
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5 4 7 1 3 2 6
in MST does not create a cycle
Consider edges in ascending order of weight.
7
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 5 4 7 1 3 2 6
in MST does not create a cycle
Consider edges in ascending order of weight.
8
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
9
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
10
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
11
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 5 4 7 1 3 2 6
in MST does not create a cycle
Consider edges in ascending order of weight.
12
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
13
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
14
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
15
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 5 4 7 1 3 2 6
in MST does not create a cycle
Consider edges in ascending order of weight.
16
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 3-6 0.52 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
17
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 3-6 0.52 6-0 0.58 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
18
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93 5 4 7 1 3 2 6
creates a cycle not in MST
Consider edges in ascending order of weight.
19
0-7 0.16 2-3 0.17 1-7 0.19 0-2 0.26 5-7 0.28 1-3 0.29 1-5 0.32 2-7 0.34 4-5 0.35 1-2 0.36 4-7 0.37 0-4 0.38 6-2 0.40 3-6 0.52 6-0 0.58 6-4 0.93 5 4 7 1 3 2 6 a minimum spanning tree