CS3000: Algorithms & Data Jonathan Ullman
Lecture 13:
- Minimum Spanning Trees
Mar 9, 2020
CS3000: Algorithms & Data Jonathan Ullman Lecture 13: Minimum - - PowerPoint PPT Presentation
CS3000: Algorithms & Data Jonathan Ullman Lecture 13: Minimum Spanning Trees Mar 9, 2020 Midterm II In Class Wednesday March 25 th Working on a backup plan Exactly the same format/rules as Midterm I Topics: Graph
Lecture 13:
Mar 9, 2020
such that !, 0 forms a tree
nodes
potentialedges
edge
costs
Henesinter IT
we
3 53
6
7 18
9
15
I
add cheapest edge out of each connected component
cheapest edge that grows the connected component
ascending order, adding edges unless they create a cycle
descending order, deleting edges unless it disconnects
Cycle C = (1,2),(2,3),(3,4),(4,5),(5,6),(6,1)
1 3 8 2 6 7 4 5
1 3 8 2 6 7 4 5
Cut S = {4, 5, 8} Cutset = (5,6), (5,7), (3,4), (3,5), (7,8)
S
number of edges
disconnect any nodes
O
O
weight edge cut by 7. Then the MST 0∗ contains 9
maximum weight edge in :. Then the MST 0∗ does not contain ;.
weight edge cut by 7. Then the MST 0∗ contains 9
; 0∗ 9 7
remove f
Assume T
is the MST and
it doesnt
contain
e
__
If we add
e
to
T
there must
be a
cycle C
C contains
72 edges
crossing the
ut
se f3
w f
sole If we
remove f from
T uEe3 the the total we
is lower than T
is still a tree is
weight edge in :. The MST 0∗ does not contain ;.
; 0∗ 9 7
Proof by
contradiction
Assume T
is the
MST and
contains
If
we remove f
the graph THEM
has two
components 5,5
There is
some
edge etc
et by
S
utle
cut Cf
Thus
T 173 use
is
a spanning hee 4
low
weight
a
weight, then 9 is always in the MST 0∗
weight, then ; is never in the MST 0∗
Suppose
T
is
not
connected
Then it has multiple
ied
crossing the art
is a safeedge
5
iii
Br Ce
Will contain duplicates
1 2 6 3 5 4 7 8
Label Connected Components
1 2 6 3 5 4 7 8
Add Safe Edges
1 1 1 2 1 2 1 1
Label Connected Components
1 1 1 2 1 2 1 1
Add Safe Edges
1 1 1 1 1 1 1 1
Done!
ntm
BFS thegraph tofind components
Loopthrough edges keeptrack of
m n ut edgefor
each component
FindSafeEdges(G,T): find connected components =>, … , =? let L[v] be the component of node @ Let S[i] be the safe edge of =A for each edge (u,v) in E: If L[u] ≠ L[v]: If w(u,v) < w(S[L[u]]): S[L[u]] = (u,v) If w(u,v) < w(S[L[v]]): S[L[v]] = (u,v) Return {S[1],…,S[k]}
HusingBFS Dfs
Hln I
rally 4
May have duplicates
number of connected components.
atleast
If the
claim
is
true
then
iterations
I Llogzln
V E
is connected
so
Ms
n
l
htm E 2am11 04
ntm
per iteration
add # to 7
s
So Eos
Prim(G=(V,E)) let Q be a priority queue storing V value[v] ← ∞, last[v] ←⊥ value[s] ← G for some arbitrary H while (Q ≠ ∅): u ← ExtractMin(Q) for each edge (u,v) in E: if v ∈ Q and w(u,v) < value[v]: DecreaseKey(v,w(u,v)) last[v] ← u T = {(1,last[1]),…,(n,last[n])} (excluding s) return T
n
m
n
Extract nm
m
Decreasekey
components add 9 to 0
we can efficiently perform two operations:
components add 9 to 0