Minimum Spanning Trees

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Advertisements

Minimum Spanning Tree CSE 331 Section 2 James Daly.
Chapter 23 Minimum Spanning Trees
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
CSE 421 Algorithms Richard Anderson Dijkstra’s algorithm.
1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Analysis of Algorithms CS 477/677
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
Design and Analysis of Algorithms Minimum Spanning trees
Tirgul 13 Today we’ll solve two questions from last year’s exams.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Introduction to Graph Theory
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
Running Time of Kruskal’s Algorithm Huffman Codes Monday, July 14th.
1 Chapter 4 Minimum Spanning Trees Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
November 13, Algorithms and Data Structures Lecture XII Simonas Šaltenis Aalborg University
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Minimum Spanning Trees Problem Description Why Compute MST? MST in Unweighted Graphs MST in Weighted Graphs –Kruskal’s Algorithm –Prim’s Algorithm 1.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
Greedy Algorithms General principle of greedy algorithm
Lecture ? The Algorithms of Kruskal and Prim
Introduction to Algorithms
Minimum Spanning Trees
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
CSC 413/513: Intro to Algorithms
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Autumn 2015 Lecture 10 Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Greedy Algorithms Comp 122, Spring 2004.
Autumn 2016 Lecture 10 Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Minimum Spanning Trees Prim’s Algorithm Kruskal’s Algorithm Wed, July 9th

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Tree Definition: An undirected graph G(V, E) is a tree iff G is connected G is acyclic

Example: Tree (1)

Example: Not a Tree (1)

Example: Not a Tree (2)

Example: Tree (2)

Example: Not a Tree (3)

Example: Tree (3)

Example: Not a Tree (3)

Removing any edge (u, v) from a tree T disconnects T! Breaking a Tree Lemma Removing any edge (u, v) from a tree T disconnects T! Why? No u⤳v path can exist! Assume it did… u x1 x2 v Contradicts acyclicity of T!

Then G is acyclic and hence a tree. Reverse is Also True Let G be a connected graph and assume removing any edge from G disconnects it. Then G is acyclic and hence a tree. Why? x1 xi xi+1 xk Claim: G cannot contain a cycle C

Proof That G Cannot Contain a Cycle C Breaking a Cycle Lemma: Removing any edge from a cycle cannot disconnect a connected graph! x1 xi xi+1 xk Take (xi xi+1), and any path P that was using it xi xi+1 t S

Proof That G Cannot Contain a Cycle C Breaking a Cycle Lemma: Removing any edge from a cycle cannot disconnect a connected graph! x1 xi xi+1 xk Take (xi xi+1), and any path P that was using it xi xi+1 t S

s and t are still connected! Proof That G Cannot Contain a Cycle C Breaking a Cycle Lemma: Removing any edge from a cycle cannot disconnect a connected graph! x1 xi xi+1 xk Take (xi xi+1), and any path P that was using it xi xi+1 t S s and t are still connected! xi-1 xk x1

Adding any edge (u, v) to a tree T creates a cycle! Cycle Creation Lemma Adding any edge (u, v) to a tree T creates a cycle!

Adding any edge (u, v) to a tree T creates a cycle! Cycle Creation Lemma Adding any edge (u, v) to a tree T creates a cycle!

Adding any edge (u, v) to a tree T creates a cycle! Cycle Creation Lemma Adding any edge (u, v) to a tree T creates a cycle! Proof: B/c T is connected, ∃path P from u to v. u v adding (u, v) closes the cycle.

Every tree of n vertices contains n-1 edges! Theorems Every tree of n vertices contains n-1 edges! Every n-1 acyclic set of edges is a tree => i.e., they connect V!

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Minimum Spanning Tree Input: undirected G(V, E) and arbitrary weights on the edges Output: A tree T* of V such that w(T*) ≤ any other T of V w(T) = sum of the weights of all n-1 edges in T “spanning” tree of G(V, E) means T* has to connect all of V Assumptions: G is connected (minor) Edge weights are distinct (all of our algorithms work w/o this assumption)

Spanning Tree Example A D B C 1 2 4 2.5 3 5

Spanning Tree Example A D B C 1 2 4 2.5 3 5

Spanning Tree Example A D C 1 4 2.5 B C 1 4 2.5 W((A,C), (C,B), (B,D)) = 1 + 2.5 + 4 = 7.5

Spanning Tree Example A D B C 1 2 4 2.5 3 5

Spanning Tree Example A D C 1 2 4 B C 1 2 4 W((A,C), (C,D), (B,D)) = 1 + 2 + 4 = 7

MST Applications Designing all kinds of networks: datacenter networks road networks phone networks Circuit Design Clustering Image Segmentation …

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Prim’s Algorithm Simulation (1) ?

Prim’s Algorithm Simulation (1) B C 1 4 6 D

Prim’s Algorithm Simulation (1) D E 1 2 6 5 4 C B

Prim’s Algorithm Simulation (1) D E 1 2 3 6 5 4 F C B

Prim’s Algorithm Simulation (1) D E 1 2 3 6 5 4 2.5 F C B 7.5 G

Prim’s Algorithm Simulation (1) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G

Prim’s Algorithm Simulation (1) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G

Prim’s Algorithm Simulation (1) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G 9

Prim’s Algorithm Simulation (1) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G 9

Prim’s Algorithm Simulation (1) D E 1 2 3 4 2.5 F C B 7 7.5 Final Tree! H G

Prim’s Algorithm procedure prim(G(V, E)): choose any s∈V let L={s}, R=V-{s} T = {} // final tree edges for i = 1 to n: 1. let (u, v) be the min cost edge crossing L-R 2. remove v from R and add to L 3. add (u, v) to T return T

Prim’s Algorithm Simulation (2) ?

Prim’s Algorithm Simulation (2) ∞ A B C 1 4 6 D

Prim’s Algorithm Simulation (2) 1 6 4 A B C D

Prim’s Algorithm Simulation (2) D E 1 2 ∞ 6 5 4 4 6 C B

Prim’s Algorithm Simulation (2) D E 1 2 2 6 5 4 4 5 C B

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 4 F 5 ∞ C B

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 4 F 5 3 C B

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 4 F 5 C B 7.5 ∞ G

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 4 F 2.5 C B 7.5 7.5 G

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 8 4 F C B 7 7.5 H ∞ 7.5 G

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 8 4 F C B 7 7.5 H 7 7.5 G

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H 7 7.5 G

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H 7.5 G 9

Prim’s Algorithm Simulation (2) D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G 9

Prim’s Algorithm Simulation (2) D E 1 2 3 4 2.5 F C B 7 7.5 Final Tree! H G

Prim’s Algorithm procedure prim(G(V, E)): choose any s∈V let L={s}, R=V-{s} let mWE store for each vertex in R, its min weight edge to L. T = {} // final tree edges for i = 1 to n: 1. let v be min mWE vertex let (u, v) be the edge minimizing v’s mWE 2. remove v from R & mWE;add to L 3. add (u, v) to T 4. update mWE for each neighbor of v in R return T

Exactly the same As Dijkstra’s Algorithm! Prim’s Algorithm Running Time Exactly the same As Dijkstra’s Algorithm! O((n+m)log(n)) = O(mlog(n)) when using a priority queue backed with a heap to store “mWE” values When a vertex y is moved from R to L, For each (x, y): Dijkstra Update: val[y]=min{val[y], shortDist[x] + w((x, y))} Prim Update: val[y]=min{val[y], w((x, y))}

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Cuts A cut of G(V, E) is a slice of V into 2 non-empty sets A D B C 1 2 4 2.5 3 5

Cuts A cut of G(V, E) is a slice of V into 2 non-empty sets A D B C 1 2 4 2.5 3 5

Cuts A cut of G(V, E) is a slice of V into 2 non-empty sets A D B C 1 2 4 2.5 3 5

⇔ Empty Cut Lemma ∃ cut (X, Y) with no crossing edges A graph G(V, E) is not connected ⇔ [prove as exercise]

Claim: Then there is another e` ≠ e of C that also crosses (X, Y) Double Cut Crossing Lemma of Cycles Suppose a cycle C⊆ E has an edge e crossing a cut (X, Y) Claim: Then there is another e` ≠ e of C that also crosses (X, Y)

Double Cut Crossing Lemma of Cycles X Y e v u e` u` v`

Lonely Cut Corollary Suppose there is a cut (X, Y) which has only one edge e crossing it Claim: e cannot be part of any cycle C!

Lonely Cut Corollary Claim: e cannot be part of any cycle C! X Y e v u

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

For Correctness We Need To Prove 2 Things Outputs a Spanning Tree Tprim Tprim is a minimum spanning tree

1: Prim Outputs a Spanning Tree Proof: At each iteration i, Tprim,i spans Li AND is acyclic By induction: Holds for base case s Ind. Hyp. (IH).: Tprim,k spans L after kth iteration Prim picks the min edge (u, v) from Lk to Rk. By IH: u has a path to every vertex in Lk and vice versa => with addition of (u, v), v has a path to every vertex in Lk and vice versa => Tprim,k+1 is spanning Tprim,k+1 is acyclic b/c (u, v) is the first edge from Lk to Rk (by the lonely cut corollary) Q.E.D

Plan for 2: Tprim is a Minimum Spanning Tree “Cut Property” of Edges Argue that the Cut Property Implies Tprim is an MST

Claim: e belongs to every MST Cut Property of Edges Consider any cut (X, Y) of G, and suppose e is the minimum edge crossing (X, Y) Claim: e belongs to every MST

Cut Property of Edges X Y 1 8 3 4 5

Cut Property of Edges (u,v) belongs to every MST! X Y 1 u v 8 3 4 5

Cut Property => Tprim is a MST ?

Cut Property => Tprim is a MST B C 1 4 6 D

Cut Property => Tprim is a MST D E 1 2 6 5 4 C B

Cut Property => Tprim is a MST D E 1 2 3 6 5 4 F C B

Cut Property => Tprim is a MST D E 1 2 3 6 5 4 2.5 F C B 7.5 G

Cut Property => Tprim is a MST D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G

Cut Property => Tprim is a MST D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G

Cut Property => Tprim is a MST D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G 9

Cut Property => Tprim is a MST D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 H G 9

Cut Property => Tprim is a MST Prim looks at n-1 different cuts. Add n-1 edges that every MST includes. Since any spanning tree include n-1 edges => Tprim is “the” MST. (with distinct edge weights this proof also proves the uniqueness of MST)

Proof of Cut Property (Exchange Argument) e=min u v internal edges and vertices of X internal edges and vertices of Y

Proof of Cut Property (Exchange Argument) Let T be any MST that doesn’t contain e X Y e=min u v internal edges and vertices of X internal edges and vertices of Y

Proof of Cut Property (Exchange Argument) Let T be any MST that doesn’t contain e X Y u v internal edges of T in X internal edges of T in Y

Proof of Cut Property (Exchange Argument) add e to T X Y u v internal edges of T in X internal edges of T in Y By cycle creation lemma we created a cycle.

Proof of Cut Property (Exchange Argument) add e to T X Y u v internal edges of T in X internal edges of T in Y b a By Double Crossing Lemma ∃(a, b) that also crosses (X, Y)

Proof of Cut Property (Exchange Argument) v internal edges of T in X internal edges of T in Y b a Claim: Can safely remove (a, b) and still get a spanning tree. Why?

Proof of Cut Property (Exchange Argument) v internal edges of T in X internal edges of T in Y b a By Breaking a Cycle Lemma we can’t disconnect T ∪ (u, v)!

Proof of Cut Property (Exchange Argument) T` = T + (u, v) – (a, b) X Y u v internal edges of T in X internal edges of T in Y b T` is still a spanning tree and w(T`) < w(T) a

=> Every MST has to include e! Proof of Cut Property (Exchange Argument) Started with (X, Y) cut, and e=(u, v): min edge crossing (X, Y) Took any minimum spanning tree T that did not include e. Added e to T => created a cycle C (by cycle-creation-lemma) By DCL, there is another edge e` that crosses (X, Y) Removed e` => T` By Breaking A Cycle Lemma: T` is still connected Therefore w(T`) < w(T) => T was not an MST. => Every MST has to include e! Q.E.D.

Summary of Prim’s Algorithm’s Correctness First proved Tprim is a spanning tree By induction on Li Second proved Tprim is a an minimum spanning tree Note this version of Prim’s Correctness Proof contains: Exchange Argument: Cut Property Greedy Stays Ahead Argument: Prim adds n-1 edges and stay ahead at each addition.

Outline For Today Graph Theory Part 1: Trees & Properties of Trees Minimum Spanning Trees Prim’s Algorithm And Run-time Analysis Graph Theory Part 2: Cuts & Properties of Cuts Prim’s Algorithm’s Correctness & “The Cut Property” Kruskal’s Algorithm

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G Creates a cycle 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G Creates a cycle 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G Creates a cycle 9

Kruskal’s Algorithm Simulation D E 1 2 3 6 5 4 2.5 8 F C B 7 7.5 1, 2, 2.5, 3, 4, 5, 6, 7, 7.5, 8, 9 H G Creates a cycle 9

Kruskal’s Algorithm Simulation D E 1 2 3 4 2.5 F C B 7 Final Tree! Same as Tprim 7.5 H G

Kruskal’s Algorithm Pseudocode procedure kruskal(G(V, E)): sort E in order of increasing weights rename E so w(e1) < w(e2) < … < w(em) T = {} // final tree edges for i = 1 to m: if T ∪ ei=(u,v) doesn’t create cycle add ei to T return T

For Correctness We Need To Prove 2 Things Outputs a Spanning Tree Tkrsk Tkrsk is a minimum spanning tree

1: Kruskal Outputs a Spanning Tree (1) Need to prove Tkrsk is spanning AND is acyclic Acyclic is by definition of the algorithm. Why is Tkrsk spanning (i.e., connected)? Recall Empty Cut Lemma: A graph is not connected iff ∃ cut (X, Y) with no crossing edges If all cuts have a crossing edge -> graph is connected!

1: Kruskal Outputs a Spanning Tree (2) Consider any cut (X, Y) Since input G is connected, ∃ edges crossing (X, Y) Let e* be the min-weight edge Kruskal inspects all edges Consider the time when Kruskal inspects e* Claim: No edge crossing (X, Y) is in Tkrsk And adding e* to Tkrsk cannot create a cycle => Why? (because of lonely cut corallary) Therefore Kruskal will add e*, so for each cut, there is an edge in Tkrsk crossing it => Tkrsk spans V.

Plan for 2: Tkrsk is a Minimum Spanning Tree Argue that the Cut Property Implies Tkrsk is an MST In particular we will argue that each edge (u, v) added to Tkrsk is a min-edge in a cut (X, Y) in G.

Cut Property => Tkrsk is a MST (1) Let (u, v) be any edge added by Kruskal’s Algorithm. u and v are in different comp. (b/c Kruskal checks for cycles) Claim: (u, v) is min-edge crossing this cut! v t z w u x y

Cut Property => Tkrsk is a MST (2) (u, v) is the min edge crossing the cut b/c Kruskal looks at edges in increasing weights. By the Cut Property => (u, v) is in every MST. Therefore all edges added to Tkrsk is in every MST => Tkrsk is “the” MST. Q.E.D.

Summary of Kruskal’s Correctness First proved Tkrsk is a spanning tree Acyclicity was by definition Connectedness followed from showing that there is an edge of Tkrsk crossing any cut (X, Y) of G, which by the empty cut lemma implied that Tkrsk was connected Second proved Tkrsk was a minimum spanning tree by arguing that any edge (u, v) if Tkrsk is a min-edge in some cut (X, Y) Note this version of Kruskal’s Correctness Proof contains: Exchange Argument: Cut Property Greedy Stays Ahead Argument: Krusk adds n-1 edges and all are justified.

Kruskal’s Algorithm Pseudocode procedure kruskal(G(V, E)): sort E in order of increasing weights rename E so w(e1) < w(e2) < … < w(em) T = {} // final tree edges for i = 1 to m: if T ∪ ei=(u,v) doesn’t create cycle add ei to T return T

Kruskal’s Algorithm Naïve Run-time O(mlog(n)) to sort the edges m iterations O(n) time to check for a cycle (BFS/DFS) Total: O(mn) total time On Monday will improve to O(mlog(n))