Note06

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: om Topt , we change Topt , without increasing the weight in the process, to another MST T that contains e1 . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 17 / 49 Greedy Choice Property for Kruskal's Algorithm Let e1 , e2 , . . . , em be the edge list in the order of increasing weight. So e1 is the first edge chosen by Kruskal's algorithm. Let Topt be an MST of G. By definition, the total weight of Topt is the minimum. We want to show Topt contains e1 . But this is not always possible. Recall that the MST of G is not unique. So we will do this: Starting from Topt , we change Topt , without increasing the weight in the process, to another MST T that contains e1 . If Topt contains e1 , then we are done (lucky!) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 17 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. Then T is a spanning tree of G. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. Then T is a spanning tree of G. Since e1 is the edge with the smallest weight, w(e1 ) w(ei ). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. Then T is a spanning tree of G. Since e1 is the edge with the smallest weight, w(e1 ) w(ei ). Hence w(T ) = w(Topt ) - w(ei ) + w(e1 ) w(Topt ). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. Then T is a spanning tree of G. Since e1 is the edge with the smallest weight, w(e1 ) w(ei ). Hence w(T ) = w(Topt ) - w(ei ) + w(e1 ) w(Topt ). But Topt is a MST! c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. Then T is a spanning tree of G. Since e1 is the edge with the smallest weight, w(e1 ) w(ei ). Hence w(T ) = w(Topt ) - w(ei ) + w(e1 ) w(Topt ). But Topt is a MST! So we must have w(ei ) = w(e1 ) and w(Topt ) = w(T ). In other words, both Topt and T are MSTs of G. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm Suppose Topt does not contain e1 . Consider the graph H = Topt {e1 }. H contains a cycle C. Let ei = e1 be another edge on C. Let T = Topt - {ei } {e1 }. Then T is a spanning tree of G. Since e1 is the edge with the smallest weight, w(e1 ) w(ei ). Hence w(T ) = w(Topt ) - w(ei ) + w(e1 ) w(Topt ). But Topt is a MST! So we must have w(ei ) = w(e1 ) and w(Topt ) = w(T ). In other words, both Topt and T are MSTs of G. This is what we want to show: There is an MST that contains e1 . So when Kruskal's algorithm includes e1 into T, we are not making a mistake. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 18 / 49 Greedy Choice Property for Kruskal's Algorithm ei e1 c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 19 / 49 Correctness Proof of Kruskal's Algorithm The proof is by induction. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 20 / 49 Correctness Proof of Kruskal's Algorithm The proof is by induction. Kruskal's algorithm selects the lightest edge e1 = (x, y). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 20 / 49 Correctness Proof of Kruskal's Algorithm The proof is by induction. Kruskal's algorithm selects the lightest edge e1 = (x, y). By Greedy Choice Property, there exists an optimal MST of G that contains e1 . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis an...
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 431/531 taught by Professor Xinhe during the Fall '11 term at SUNY Buffalo.

Ask a homework question - tutors are online