0% found this document useful (0 votes)
2 views7 pages

Csci3100 Day26

5

Uploaded by

priya.umd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Csci3100 Day26

5

Uploaded by

priya.umd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

11/2/2018

Prim’s Algorithm Example


More Proofs
Application of MST to Clustering
CSCI 3100

Prim’s algorithm with priority queue

1
11/2/2018

Prim’s algorithm example: r = 1


A A.key =0 A.π = NIL
6 5 B.key = ∞ B.π = NIL
1 C.key = ∞ C.π = NIL
C
B D.key = ∞ D.π = NIL
5 5
D E.key = ∞ E.π = NIL
3 6 2 F.key = ∞ F.π = NIL
4
Q=ABCDEF
E F u = EXTRACT_MIN(Q)
6
u=A

Prim’s algorithm example: r = 1


Q=BCDEF
For each v in G.Adg(A)
A if v in Q and w (u, v) < v.key
6 5 v. π = u
1 v.key = w(u,v)
C
B (A, B): B is in Q, w(A,B) < B.key
5 5
D B. π = A, B.key = 6, Q = B C D E F
3 6 2 (A, D): D is in Q, w(A,D) < D.key
4
D. π = A, D.key = 1, Q = D B C E F
E F (A, C): C is in Q, w(A, C) < C.key
6 C. π = A, C.key = 5, Q = D B C E F

2
11/2/2018

B.key = 6, D.key = 1, C.key = 5, E.key = ∞,


F.key = ∞
Q=DBCEF
u = EXTRACT_MIN(Q) = D
A (D, A): A is not in Q
6 5 (D, B): B is in Q, w(D,B) < B.key
1 C B. π = D, B.key = 5, Q = B C E F
B
5 5 (D, C): C is in Q, w(D, C) == C.key
D (D, E): E is in Q, w(D, E) < E.key
3 6 2
4 E. π = D, E.key = 6, Q = B C E F
(D, F): F is in Q, w(D, F) < F.key
E F
6 F. π = D, F.key = 4, Q = F B C E

B.key = 5, C.key = 5, E.key = 6, F.key = 4


Q=FBCE
u = EXTRACT_MIN(Q) = F
A (F, E): E is in Q, w (F, E) > F.key
6 5 (F, D): D is not in Q
1 C (F, C): C is in Q, w(F, C) < F.key
B
5 5 C. π = F, C.key = 2, Q = C B E
D
3 6 2
4
E F
6

3
11/2/2018

B.key = 5, C.key = 2, E.key = 6


Q=CBE
u = EXTRACT_MIN(Q) = C
A (C, A): A is not in Q
6 5 (C, D): D is not in Q
1 C (C, F): F is not in Q
B
5 5
D
3 6 2
4
E F
6

B.key = 5, C.key = 2, E.key = 6


Q=BE
u = EXTRACT_MIN(Q) = B
A (B, A): A is not in Q
6 5 (B, D): D is not in Q
1 C (B, E): E is in Q, w(B,E)<E.key
B
5 5 E. π = B, E.key = 3
D
3 6 2
4
E F
6

4
11/2/2018

Prim’s algorithm example: r = 1


A A.π = NIL
6 5 B.π = D A
1 C
C.π = F
B
5 5 D.π = A 1 C
D E.π = B B
5
3 6 2
4 F.π = D D
3 2
E F
4
6
E F

Cycle property
Claim: Assume that all edge costs are distinct. Let C be any cycle in
G = (V, E), and let edge e = (v, w) be the largest edge in C. Then e is not
in any minimum spanning tree of G.
Which of the following is NOT a good approach for a proof of this
claim?
A. Assume e is in some minimum spanning tree of G, show that this
leads to a contradiction.
B. Let T be a spanning tree containing e, show that T is not a minimum
spanning tree.
C. Assume e is not in any minimum spanning tree of G. Show that your
assumption is consistent with the rest of the facts.
D. All of the above approaches are good.

5
11/2/2018

Proof A:
Let T be a spanning tree that contains e = (v, w). We need to show that T
does not have the minimum possible weight.
Let’s delete edge e from T. This partitions the vertices of G into two
components S and V – S. Let node v be in S and node w be in V-S.
Since G has a cycle C and edge e is part of that cycle, there is a path from v to
w in G that does not involve edge e. This path will have an edge e’ with one
vertex in component S and another vertex in component V-S.
Now consider the set of edges T’ = T-{e} U {e’}. The graph (V, T’) is connected
and has no cycles, so it is a spanning tree of G. Since the weight of e > weight
e’, the weight of T’ is less than the weight of T. Therefore T is not a minimum
spanning tree.

Proof B (similar to proof A)


Assume e = (v, w) is in a minimum spanning tree T of G. (We need to show
that there is another spanning tree of G with smaller weight than T, thus
leading to a contradiction. )
Let’s delete edge e from T. This partitions the vertices of G into two
components S and V – S. Let node v be in S and node w be in V-S.
Since G has a cycle C and edge e is part of that cycle, there is a path from v to
w in G that does not involve edge e. This path will have an edge e’ with one
vertex in component S and another vertex in component V-S.
Now consider the set of edges T’ = T-{e} U {e’}. The graph (V, T’) is connected
and has no cycles, so it is a spanning tree of G. Since the weight of e > weight
e’, the weight of T’ is less than the weight of T. Therefore T is not a minimum
spanning tree. This is a contradiction. This e cannot be in a minimum
spanning tree of G

6
11/2/2018

More on proofs
• Once a property of fact is established, it can be used in later proofs
• Example: Suppose we have a situation where we have a cycle and an
edge e in the cycle with the largest weight. We can safely claim that
that edge e will not be in the MST of a graph, by the cycle property.
• Assume, without loss of generality, that all edge weights are distinct.
• Homework 4 – proof practice

Given a connected graph G, with distinct edge


weights, let n be the number of vertices in G and
m be the number of edges. A particular edge e =
(v, w) of G is specified. Give an algorithm with
running time O(m+n) to decide whether e is
contained in a minimum spanning tree of G
1. Construct G’ from G by deleting edges with weight greater than the
weight of e. Delete e as well.
2. See if there is a path from v to w in G’, then e is not included in any
MST of G. Otherwise, e is included in the MST of G.

You might also like