•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Computer Science and Software Design section within the Software Development category of DaniWeb, a massive community of 429,888 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,279 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Computer Science and Software Design advertiser: Programming Forums
Views: 1100 | Replies: 1 | Solved
![]() |
•
•
Join Date: Sep 2007
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
It's tough being 50 and back in college! If anyone has recently taken an Algorithm class, my question is this: Is the proof for Prim's algorithm any different than for Kruskal? I understand both algorithms are greedy in the sense of picking the least weight edge each itiration. Prims only adds the next least expensive edge that can connect to the existing, growing subtree, whereas Kruskal just picks the next least cost edge period, as long as it creates no cycles, so that eventually all subtrees connect.
I am finding many proofs for Kruskal (e.g. Wikipedia), but trouble finding proofs for Prim. The Kruskal proof is as far as I can see, in plain English:
1. Assume a growing, subset tree that both Kruskal and MST have in common.
2. Look at the first edge "e" = (x,y) added by Kruskal that does not yield an MST (vertex x is in common subset, vertex y is not).
3. The MST must eventually reach y using an edge "f" not in Kruskal (MST + e form a cycle with edge f in MST).
4. Since f came after e, it must be that cost f >= cost e.
5. Since MST + e froms a cycle through y, replace f with e in the MST and you still have an MST
6. Repeat process and eventually the MST morphs into Kruskal
Is the proof for Prim identical? Since the Prim algorithm is more constrained, it seems to me there should be a simpler proof for Prim?
I am finding many proofs for Kruskal (e.g. Wikipedia), but trouble finding proofs for Prim. The Kruskal proof is as far as I can see, in plain English:
1. Assume a growing, subset tree that both Kruskal and MST have in common.
2. Look at the first edge "e" = (x,y) added by Kruskal that does not yield an MST (vertex x is in common subset, vertex y is not).
3. The MST must eventually reach y using an edge "f" not in Kruskal (MST + e form a cycle with edge f in MST).
4. Since f came after e, it must be that cost f >= cost e.
5. Since MST + e froms a cycle through y, replace f with e in the MST and you still have an MST
6. Repeat process and eventually the MST morphs into Kruskal
Is the proof for Prim identical? Since the Prim algorithm is more constrained, it seems to me there should be a simpler proof for Prim?
•
•
Join Date: Oct 2007
Location: Cambridge, MA
Posts: 269
Reputation:
Rep Power: 2
Solved Threads: 22
•
•
•
•
1. Assume a growing, subset tree that both Kruskal and MST have in common.
2. Look at the first edge "e" = (x,y) added by Kruskal that does not yield an MST (vertex x is in common subset, vertex y is not).
What do you mean by "the first edge added by Kruskal that does not yield an MST?" Every edge added by Kruskal's algorithm does not yield a minimum spanning tree, _except_ for the last edge added. What do you mean by "first"?
Also, in step one, you refer to a subset tree that both "Kruskal and MST have in common." What does 'Kruskal' mean in this sentence? Kruskal is the name of a person or the name of an algorithm. You're referring to a subset tree that Kruskal's algorithm is in the process of building?
I am being pedantic, but your wording must be precise if you are to convince yourself that you're thinking clearly. And you should always be critical of your wording.
•
•
•
•
3. The MST must eventually reach y using an edge "f" not in Kruskal (MST + e form a cycle with edge f in MST).
4. Since f came after e, it must be that cost f >= cost e.
5. Since MST + e froms a cycle through y, replace f with e in the MST and you still have an MST
6. Repeat process and eventually the MST morphs into Kruskal
You're using the word "MST," which I take it means "minimum spanning tree." You mean to refer to simply a "spanning tree," not a "minimal spanning tree," right? Because if it's not minimal, it's not an MST.
•
•
•
•
Is the proof for Prim identical? Since the Prim algorithm is more constrained, it seems to me there should be a simpler proof for Prim?
It's pretty much the same kind of idea, so it takes the same length. (And the proof in both cases is short anyway.) For Prim's algorithm, let S be the set of nodes in the subtree you're building, S' be the rest of the nodes. Let F be the set of edges with one node in S and one node in S'. You can show that if you didn't pick the smallest edge in F, then you could add it later and remove one of the edges in F.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Computer Science and Software Design Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: Fingerprint image filtering
- Next Thread: Pentium


Linear Mode