1 / 11

Kruskal's and Prim's Algorithms for Minimum Spanning Trees

Learn solutions to Homework 7 and 8 related to Kruskal's and Prim's algorithms for finding Minimum Spanning Trees. Understand the conditions, assumptions, and optimality of each algorithm, explained with examples. Dive into the details of how these algorithms work step by step.

Download Presentation

Kruskal's and Prim's Algorithms for Minimum Spanning Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Input: G=(V,E), ce> 0 for every e in E T = Ø Sort edges in increasing order of their cost Joseph B. Kruskal 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), ce> 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 Condition: S and V\S are non-empty V \ S S Cheapest crossing edge is in all MSTs Assumption: All edge costs are distinct

  6. Optimality of Kruskal’s Algorithm V \ S S S Nodes connected to red in (V,T) Input: G=(V,E), ce> 0 for every e in E S is non-empty T = Ø V\S is non-empty Sort edges in increasing order of their cost First crossing edge considered Consider edges in sorted order If an edge can be added to T without adding a cycle then add it to T

  7. Kruskal’s algo outputs MST Group talk time!

  8. Is (V,T) a spanning tree? No cycles by design G is disconnected! Just need to show that (V,T) is connected V \ S’ S’ No edges here

  9. Crucial Lemma for MSTs Condition: S and V\S are non-empty V \ S S Cheapest crossing edge is in all MSTs

  10. Optimality of Prim’s algorithm S is already defined for us! By induction, show that (S,T) is a tree S not Ø Input: G=(V,E), ce> 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

  11. Prove the Crucial Lemma Condition: S and V\S are non-empty V \ S S Cheapest crossing edge is in all MSTs

More Related