0% found this document useful (0 votes)
52 views5 pages

V Adj U V Q

The document discusses minimum spanning tree (MST) algorithms including Prim's algorithm, Kruskal's algorithm, and a generic MST algorithm. It provides pseudocode for Prim's and Kruskal's algorithms. Prim's runs in O(ElogV) time and Kruskal's runs in O(ElogE) time. It also proves that if edge (u,v) crosses a cut (S,V-S) and has lower weight than any other edge crossing the cut, then (u,v) is safe to add to the growing MST.

Uploaded by

Diego Espinoza
Copyright
© Attribution Non-Commercial (BY-NC)
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)
52 views5 pages

V Adj U V Q

The document discusses minimum spanning tree (MST) algorithms including Prim's algorithm, Kruskal's algorithm, and a generic MST algorithm. It provides pseudocode for Prim's and Kruskal's algorithms. Prim's runs in O(ElogV) time and Kruskal's runs in O(ElogE) time. It also proves that if edge (u,v) crosses a cut (S,V-S) and has lower weight than any other edge crossing the cut, then (u,v) is safe to add to the growing MST.

Uploaded by

Diego Espinoza
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 5

MST-Prim(G,w,r) Q=V for each u in Q key[u]= key[r]=0 while Q is not empty u=Extract-Min(Q) for each v Adj [ u ] if v Q and w(u,v)<key[v]

[v] then key[v]=w(u,v)


4

b
11 7

c i
2 6 4

d
14

a
8

e
10

Running time: O(V+V lg V+E lg V)=O(E lg V) using balanced binary search tree for Q using fancier data structures can get O(E+V lg V)

MST-Kruskal(G,w) A= for each vertex v Make-Set(v) sort edges of E by nondecreasing weight w for each edge (u,v) in order by nondecreasing weight if Find Set ( u ) Find Set ( v ) then add (u,v) to A Union(u,v) return A
4

b
11 7

c i
2 6 4

d
14

a
8

e
10

Running time: O(V+E lg E+E(E,V))=O(E lg E) using disjoint-set union data structure

Theorem: Let A be a subset of E that is included in some MST for G. Let (S,V-S) be any cut of G that respects A and let (u,v) be a light edge crossing (S,V-S). Then (u,v) is safe for A. Proof: Let T be a MST that includes A. For contradiction, assume T does not contain (u,v). We want to construct another MST T that includes A and (u,v). Look at the path p from u to v in T. x u and v are on opposite sides of cut (S,V-S). p So, there must be some other edge of p u y that crosses this cut, say (x,y). Since (S,V-S) respects A, we know that ( x, y ) A v Let T=T-{(x,y)}+{(u,v)} T is a spanning tree since taking out (x,y) breaks T into 2 components, and adding (u,v) reconnects these 2 components T is a minimum spanning tree since w ( u, v ) w ( x, y )

Generic-MST(G,w) A= while A does not form a spanning tree nd edge (u,v) that is safe for A and add edge (u,v) to A return A How to nd safe edges? A cut (S,V-S) is a partition of V a
8 4

b
11 7

c i
2 6 4

d
14

e
10

h
8

1 7 4

A cut respects the set A if no edge in A crosses the cut


4

b
11 7

c i
2 6

d
14

a
8

e
10

An edge is a light edge crossing a cut if its weight is the minimum of any edge crossing a cut

TOPIC 18: Minimum Spanning Trees (MST)


given weighted graph G=(V,E), we want an acyclic subset T E that spans V and has minimum weight
4 8 7 1 7 4

b
11

c i
2 6

d
14

a
8

e
10 4 8 7 1

f a

b
11

c i
2 6 4

d
14

e
10

w(T)=sum of weights of Ts edges Growing a MST algorithm manages set A that is a subset of an MST at each step, algorithm determines an edge (u,v) that can be added to A while maintaining the invariant that A is a subset of an MST such edge (u,v) is called a safe edge for A

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy