1 / 21

CSE 421 Algorithms

This lecture discusses minimum spanning trees, the greedy algorithms that compute them (Prim's and Kruskal's algorithms), and the reverse-delete algorithm. It also explores the proofs of optimality and tie-breaking rules for edge costs.

westmichael
Download Presentation

CSE 421 Algorithms

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. CSE 421Algorithms Richard Anderson Lecture 11 Minimum Spanning Trees

  2. Announcements • Monday – Class in EE1 003 (no tablets)

  3. Foreign Exchange Arbitrage USD 1.2 1.2 EUR CAD 0.6 USD 0.8 0.8 EUR CAD 1.6

  4. Minimum Spanning Tree 15 t a 6 9 14 3 4 e 10 13 c s 11 20 5 17 2 7 g b 8 f 22 u 12 1 16 v Temporary Assumption: Edge costs distinct

  5. Why do the greedy algorithms work? • For simplicity, assume all edge costs are distinct • Let S be a subset of V, and suppose e = (u, v) be the minimum cost edge of E, with u in S and v in V-S • e is in every minimum spanning tree • Or equivalently, if e is not in T, then T is not a minimum spanning tree e S V - S

  6. Proof • Suppose T is a spanning tree that does not contain e • Add e to T, this creates a cycle • The cycle must have some edge e1 = (u1, v1) with u1 in S and v1 in V-S • T1 = T – {e1} + {e} is a spanning tree with lower cost • Hence, T is not a minimum spanning tree S V - S e Why is e lower cost than e1?

  7. Optimality Proofs • Prim’s Algorithm computes a MST • Kruskal’s Algorithm computes a MST

  8. Reverse-Delete Algorithm • Lemma: The most expensive edge on a cycle is never in a minimum spanning tree

  9. Dealing with the distinct cost assumption • Force the edge weights to be distinct • Add small quantities to the weights • Give a tie breaking rule for equal weight edges

  10. MST Fun Facts • The minimum spanning tree is determined only by the order of the edges – not by their magnitude • Finding a maximum spanning tree is just like finding a minimum spanning tree

  11. Divide and Conquer Array Mergesort(Array a){ n = a.Length; if (n <= 1) return a; b = Mergesort(a[0..n/2]); c = Mergesort(a[n/2+1 .. n-1]); return Merge(b, c);

  12. Algorithm Analysis • Cost of Merge • Cost of Mergesort

  13. T(n) = 2T(n/2) + cn; T(1) = c;

  14. Recurrence Analysis • Solution methods • Unrolling recurrence • Guess and verify • Plugging in to a “Master Theorem”

  15. A better mergesort (?) • Divide into 3 subarrays and recursively sort • Apply 3-way merge

  16. T(n) = aT(n/b) + f(n)

  17. T(n) = T(n/2) + cn

  18. T(n) = 4T(n/2) + cn

  19. T(n) = 2T(n/2) + n2

  20. T(n) = 2T(n/2) + n1/2

  21. Recurrences • Three basic behaviors • Dominated by initial case • Dominated by base case • All cases equal – we care about the depth

More Related