410 likes | 428 Views
Learn about Kruskal's Algorithm - adding cheapest edges without cycles, and Prim's Algorithm - growing a tree systematically. Understand components data structure and node merging.
E N D
24 4 23 9 6 18 5 11 16 8 7 14 10 21 Minimum Spanning Tree 4 9 6 5 11 8 7 G = (V, E), c(e) T, eT c(e)= 50
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 24 4 23 9 6 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 9 6 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 9 6 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 6 9 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 6 9 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 6 9 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 6 9 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle 4 24 23 6 9 18 5 11 16 8 7 ? 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle Ignore edges inside components 4 24 23 6 9 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle Ignore edges inside components 4 24 23 6 9 18 5 11 16 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle Ignore edges inside components 4 24 23 6 9 18 5 16 11 8 7 14 10 21
Kruskal’s Algorithm: Add cheapest edge that does not create a cycle Ignore edges inside components 4 24 23 6 9 18 5 16 11 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 24 4 23 9 6 18 5 11 16 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 24 4 23 9 6 18 5 11 16 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 24 4 6 23 9 18 5 11 16 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 4 24 6 23 9 18 5 11 16 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 4 24 6 23 9 18 5 11 16 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 4 24 6 23 9 18 5 11 16 8 7 14 10 21 Can remove edges between tree nodes
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 4 24 6 23 9 18 5 16 11 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 4 24 6 23 9 18 5 16 11 8 7 14 10 21
Prim’s Algorithm: Grow a tree. At each step, add cheapest edge from tree node to non-tree node 4 24 6 23 9 18 5 16 11 8 7 14 10 21
Components Data Structure Supporting Find and Merge (Union-Find) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 8, 9, 3 9 :
Components Data Structure Supporting Find and Merge (Union-Find) node-comp array comp-size array Lists of nodes 1 : 1 2 : 2 3 : 3 4 : 4 5 : 5 6 : 6 7 : 7 8 : 8 9 : 9
Components Data Structure Merge(1,2) node-comp array comp-size array Lists of nodes 1 : 1 2 : 2 3 : 3 4 : 4 5 : 5 6 : 6 7 : 7 8 : 8 9 : 9
Components Data Structure Merge(1,2) node-comp array comp-size array Lists of nodes 1 : 1, 2 2 : 3 : 3 4 : 4 5 : 5 6 : 6 7 : 7 8 : 8 9 : 9
Components Data Structure Merge(1,8) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 8, 9, 3 9 :
Components Data Structure Merge(1,8) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 8, 9, 3 9 :
Components Data Structure Merge(1,8) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 8, 9, 3 9 :
Components Data Structure Merge(1,8) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 8, 9, 3 9 :
Components Data Structure Merge(1,8) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 8, 9, 3 9 :
Components Data Structure Merge(1,8) node-comp array comp-size array Lists of nodes 1 : 1, 2, 6, 7, 8, 9, 3 2 : 3 : 4 : 4 5 : 5 6 : 7 : 8 : 9 :
1(1) 2(1) 6(1) 3(1) 4(1) 5(1) 8(1) 9(1) 7(1) Components Data Structure Pointer Version Merge(1,2)
1(1) 6(1) 3(1) 4(1) 5(1) 8(1) 9(1) 7(1) Components Data Structure Pointer Version Merge(1,2) 2
1(2) 6(1) 3(1) 4(1) 5(1) 8(1) 9(1) 7(1) Components Data Structure Pointer Version Merge(3,4) 2
1(2) 6(1) 5(1) 8(1) 9(1) 7(1) Components Data Structure Pointer Version Merge(3,4) 3 2 4
1(1) 6(1) 3(2) 5(1) 8(1) 9(1) 7(1) Components Data Structure Pointer Version Merge(1,3) 2 4
1(2) 6(1) 3(2) 5(1) 8(1) 9(1) 7(1) Components Data Structure Pointer Version Merge(1,3) 2 4