Download presentation
Presentation is loading. Please wait.
1
Lecture 27 CSE 331 Nov 6, 2009
2
Homework related stuff Solutions to HW 7 and HW 8 at the END of the lecture Turn in HW 7
3
Kruskal’s Algorithm Joseph B. Kruskal Input: G=(V,E), c e > 0 for every e in E T = Ø Sort edges in increasing order of their cost Consider edges in sorted order If an edge can be added to T without adding a cycle then add it to T
4
Prim’s algorithm Similar to Dijkstra’s algorithm Input: G=(V,E), c e > 0 for every e in E S = {s}, T = Ø While S is not the same as V Among edges e= (u,w) with u in S and w not in S, pick one with minimum cost Add w to S, e to T
5
Crucial Lemma for MSTs S S V \ S Cheapest crossing edge is in all MSTs Condition: S and V\S are non-empty Assumption: All edge costs are distinct
6
S S V \ S Optimality of Kruskal’s Algorithm Input: G=(V,E), c e > 0 for every e in E T = Ø Sort edges in increasing order of their cost Consider edges in sorted order If an edge can be added to T without adding a cycle then add it to T S S Nodes connected to red in (V,T) S is non-empty V\S is non-empty First crossing edge considered
7
Kruskal’s algo outputs MST Group talk time!
8
Is (V,T) a spanning tree? No cycles by design Just need to show that (V,T) is connected S’ V \ S’ No edges here G is disconnected!
9
Crucial Lemma for MSTs S S V \ S Cheapest crossing edge is in all MSTs Condition: S and V\S are non-empty
10
Optimality of Prim’s algorithm Input: G=(V,E), c e > 0 for every e in E S = {s}, T = Ø While S is not the same as V Among edges e= (u,w) with u in S and w not in S, pick one with minimum cost Add w to S, e to T S is already defined for us! S not Ø By induction, show that (S,T) is a tree
11
Prove the Crucial Lemma S S V \ S Cheapest crossing edge is in all MSTs Condition: S and V\S are non-empty
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.