Lecture 5: How to prove greedy algorithms
We have two Minimal Spanning Tree algorithms: Kruskal’s (many trees) and Prim’s (single tree). Since we covered the proof of Kruskal’s algorithm in the previous lecture, we’d like to show that Prim’s algorithm produces an MST.
Setup of proof:
TPrim = {p1, … , pn-1}
TMST = {m1, … , mn-1}
Basic strategy: assume that the two trees are different, and try to get a contradiction. Let pi be an edge not in TMST. If we add pi to the MST, we get a cycle. If we add pi then take out mj from the cycle we still have a spanning tree.
Specific cases:
- |pi| < |mj| => contradiction, because we have made a less cost MST
- |pi| = |mj| => we’ve built a new MST that uses pi: sloppy.
The easiest way to resolve this is define pi so that it can’t fit into any MST, so that then there is a contradiction. Just add, “Let pi be the first Prim edge that cannot be included with {p1, … , pi-1} in any MST.”
- |pi| > |mj| => want to say that we should have picked mj
Because pi was picked by Prim’s algorithm, one of pi’s endpoints is in the tree TPrim at step i-1.
- Make sure mj is connected
- and not already in the tree
Walk around the edges of cycle, passing edges in {p1, … , pi-1}. The next edge after these is connected, too. mj has to exist because entire cycle cannot be edges of {p1, … , pi}.
Implementation details:
We need to keep a priority queue (PQ) of vertices waiting to be added. We need extract_min and update_priority functions in O(log n) time, which can be done easily with a min/max heap. For each vertex, its priority is the length of the edge connecting it to the tree. Therefore, the runtime (asymptotic complexity) of Prim’s algorithm is O(m log n) with m edges and n vertices. Compare to Kruskal’s algorithm.
This entry was posted on Wednesday, February 2nd, 2005 at 12:25 pm and is tagged with pi lt, asymptotic complexity, minimal spanning tree, tmst, priority queue, implementation details, kruskal, tree algorithms, two trees, single tree, vertices, endpoints, mj, contradiction, vertex, algorithm, p1, heap, pq, proof. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback.
2 Responses to 'Lecture 5: How to prove greedy algorithms'
Leave a Reply
Please take time to enjoy the archives: May 2005 (1) April 2005 (11) March 2005 (11) February 2005 (15) January 2005 (7)
Fresh, related resources:
- Dealbreaker - A Wall Street Tabloid - Business News Headlines and b.../b
Only When Morgan Stanley Employees bProve/b They Can Be Trusted With Internal Information Such As 'We're In The Toilet' Will Morgan Stanley Employees Be Privy To Such Information. Posted by Bess Levin, Nov 13, 2008, 3:21pm. Picture 179.png b.../b - Bash the bgreedy/b scapegoat | Herald Sun Andrew Bolt Blog
4. This blecture/b against bgreedy/b executives come from a Prime Minister who, along with his wife, is worth $60 million. b5/b. The greed Rudd denounces is in fact the hope of gain that underwrites so much of human prosperity, b.../b - TPMCafe | Talking Points Memo | Five Aspects of the Conservative State
I'm a freshman at the University of Nebraska and Thomas Frank came here to give a blecture/b just a week and a half ago. The next day my international relations class of just over 20 people got to sit down and casually talk with him. b.../b - bLecture/b 1: Cheating with foams « tcs math - some mathematics of b.../b
b5/b Comments ». [...] and near-optimal foams Filed under: Uncategorized ? jrluw @ 2:09 am In the last blecture/b, we reduced the problem of cheating in (the k-times repeated m-cycle game) to finding a small set [...] Pingback by bLecture/b 2: b.../b - Political Punch
I know better and can bprove/b it. Ask John McCain why his campaign manger Davis worked five years to avoid deregulation of Wall Street companies??? John is very heavily connected to deregulation and all this causes this stock market b.../b

on May 14th, 2005 at 9:42 pm
[…] ains a proof that Kruskal’s algorithm produces an MST, lecture 5 proves the same for Prim’s algorithm, and lecture 6 carefully proves […]
on November 12th, 2008 at 10:20 pm
9unxyug7hpkfm98f