Example of Mst 6 12 14 15 10 c 2001 by Charles E Leiserson Introduction to Agorithms Day 27 L16.6
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 27 L16.6 Example of MST 6 12 5 14 3 8 10 15 9 7
Optimal substructure MST T (Other edges ofG are not shown. Remove any edge(u, v)E T. Then, T is partitioned into two subtrees t, and t' Theorem. The subtree T, is an MST,=(V1,El the subgraph of G induced by the vertices of Ti V= vertices of t' E1={(x2y)∈E:x,y∈V1} Similarly ly for T' c 2001 by Charles E Leiserson Introduction to Agorithms Day27L16.7
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 27 L16.7 u v Remove any edge Remove any edge (u, v) ∈ T. Then, T is partitioned into two subtrees T1 and T2. T1 T2 u v Optimal substructure MST T: (Other edges of G are not shown.) Theorem. The subtree T1 is an MST of G1 = (V1, E1), the subgraph of G induced by the vertices of T1: V1 = vertices of T1, E1 = { (x, y) ∈ E : x, y ∈ V1 }. Similarly for T2
Proof of optimal substructure Proof. Cut and paste ()=(l23y)+w(71)+w(72) If Ti were a lower-weight spanning tree than T, for 1, then T'=l(u,DUTUT2 would be a lower-weight spanning tree than T for G. L Do we also have overlapping subproblems? Y es Great then dynamic programming may work Yes, but MsT exhibits another powerful property which leads to an even more efficient algorithm c 2001 by Charles E Leiserson Introduction to Agorithms Day 27 L16.8
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 27 L16.8 Proof of optimal substructure w(T) = w(u, v) + w(T1) + w(T2). Proof. Cut and paste: If T1′ were a lower-weight spanning tree than T1 for G1, then T′ = {(u, v)} ∪ T1′ ∪ T2 would be a lower-weight spanning tree than T for G. Do we also have overlapping subproblems? •Yes. Great, then dynamic programming may work! •Yes, but MST exhibits another powerful property which leads to an even more efficient algorithm
Hallmark for“ greedy” algorithms Greedy-choice property a locally optimal choice is globally optimal Theorem. Let t'be the MstofG-(v, e) and let A cv. Suppose that(u, v)E E is the least-weight edge connecting A to V-A Then,(23y)∈T c 2001 by Charles E Leiserson Introduction to Agorithms Day 27 L16.9
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 27 L16.9 Hallmark for “greedy” algorithms Greedy-choice property A locally optimal choice is globally optimal. Theorem. Let T be the MST of G = (V, E), and let A ⊆ V. Suppose that (u, v) ∈ E is the least-weight edge connecting A to V – A. Then, (u, v) ∈ T
Proof of theorem Proof Suppose(u,v)E T. Cut and paste T ∈A d8(u, v)=least- weight edge ∈ connecting a to v-A c 2001 by Charles E Leiserson Introduction to Agorithms Day 27 L16.10
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 27 L16.10 Proof of theorem Proof. Suppose (u, v) ∉ T. Cut and paste. ∈ A ∈ V – A T: u v (u, v) = least-weight edge connecting A to V – A