Algorithm Design & Analysis: Prim's Algorithm - Proof of Correctness

Hi peers,

Prim’s Algorithm is for finding the minimum spanning tree (MST) of a graph. It is simple, straightforward, and powerful. It always gives us the correct MST for an input graph every time. However, you cannot conclude that this algorithm is correct simply because it is correct for only several cases that you tested.
We have to prove its correctness with some level of formality and rigor. In this short essay, I hope you could derive as great joy as I did by appreciating the subtlety and beauty in this proof. To prove Prim’s, we have to introduce several new concepts.
Concepts that help in proof:

Concept1: Cut
A cut of a graph is a partition of the graph into two non-empty sets.
Notation Cut(A, B) denotes a cut that partitions the original graph into subgraph A and subgraph B.

Concept2: An important Property of Cut
Consider an undirected and weighted graph G(V, E). Cut(A, B) is an arbitrary cut of a graph and Edge e is an edge that crosses subgraph A & B. If e has the minimum cost among all edges that cross A & B, then e belongs to the MST of G.

Well, if you stare at Concept2, you might find it obvious that: if Concept2 is true, Prim’s Algorithm must be true. Why? Because the only thing that Prim’s algorithm is doing is: separating the graph into two subgraphs and figuring out the minimum cost edge which crosses two subgraphs. Now, if you tell me that the minimum cost edge must belong to MST of G, then Prim’s Algorithm must be always correct at finding MST.
Now, let’s prove the correctness of Concept2, because we know the correctness of Prim’s algorithm is established on Concept2. In the following, we prove by contradiction.

Setup:
Given an arbitrary Cut(A, B) in an undirected and weighted graph G(V, E), we have an minimum cost edge e* that crosses subgraph A&B. Let µ* denote the minimum spanning tree of G.
Assume the proposition “If an edge e = e*, then e belongs to MST” (proposition1) is false.
Then, the proposition “If edge e = e*, then e does NOT belong to the MST, µ*”(proposition2) must be true.

Proof:
Because µ* is the MST of G, µ* must have one edge (denoted as e’) that crosses the subgraph A&B. Notice that e’ is not equal to e*, because proposition2 is true. Also notice that e’ and e* are in a cycle, because the two end vertices of e’ are in µ* (MST includes all vertices in G).
If we now delete e’ from µ* and add e’ into µ*, we get another spanning tree (denoted as µ) that spans the whole graph. This spanning tree µ has a lower total cost than µ*, because the cost of e* < the cost of e’ (remember e* is the minimum cost edge). This fact contradicts that µ* is the MST of G.

We conclude that the proposition2 leads this the contradiction. Thus, proposition2 must not be true, which means the proposition1 must be true. By this, we complete the proof for Concept2.

We have discussed that, if the Concept2 is true, Prim’s Algorithm must be correct. Thus, we also complete the proof of correctness for Prim’s Algorithm. Q.E.D.

All the above proof are written by myself with a reference to this website: https://www.commonlounge.com/discussion/614bbd3cc5fb41639b6c8c907ebec7d5

Best,
Ben

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值