Presentation is loading. Please wait.

Presentation is loading. Please wait.

Richard Anderson Lecture 11 Minimum Spanning Trees

Similar presentations


Presentation on theme: "Richard Anderson Lecture 11 Minimum Spanning Trees"— Presentation transcript:

1 Richard Anderson Lecture 11 Minimum Spanning Trees
CSE 421 Algorithms 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 USD EUR CAD ------ 0.8 1.2 1.6 0.6 ----- 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/ 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


Download ppt "Richard Anderson Lecture 11 Minimum Spanning Trees"

Similar presentations


Ads by Google