G
=(VE) ,
•
Ks
u .ve
V
Thursday , Jan
.
Definition
contain
se g . loop ↳
A doesn’t
multi – edm .
graph
simple graph
.
i s maltiedges
o r
self- loops.
✓ Nth
Ky that
connected
: I
path from u
to V
,
fairer
D-efinition
( cent
:
A each
is
weighted
graph
a graph for
which
EE has
w Cair)
weight
: Vxv→ IR
edge
a
i w
”
Et
“””
”
”
‘
AtEEEGdAHj
O n
-R
for all u EV :
entatio o n e
epres
array Ad; of 1H lists, per
all vertices
A- rofsize NlbyNl
Ad;Cu] contains
v set
Adjacency Matrix Representation
34
vertex
Curlee .
→3z4
A matrix if(i’d)EE 2IOll
. g.tdi;={I
O otherwise
– 3→I→2 4→2→,
, 2
4→I→3
1 2
I O l l l
3l lOO yllOO
→→
GRAPHS REPR.es#tW’
1
-Adjacency list I
μμ ¥3
→
→ → →
12.71 → 11,41
14.61
13,51
(UN) i 2
→ →
13,41
11.71 →
u s,
4.61
–
edge store ✓
and weight whirl together
14,21 4 → 12,21
I
for
3
→ 2
in adjacency list
Adjacency matrix
– for edge list ,
of u
set di; =
34
•
74
f
7
05
2
4
5
•
•
6
2
x
x
– if no edge
EE Ciii) ,
whilst set dis’ =D
,
2 3
4
f# .
– }
M INIMUmWEIGHTSPANNINGTREE#
a
tv ,
..
in
.
.vn
Foreman.in fo. ” • have cost w (vi.V;)
p
¥T
Example :
DEI CMSTI
Spanning
C E is a spanning tree of G if CV T) is.IM”
,
connected.
weighted graph.
.
Let G he
T
if
=
( ) tree a so Cdfffdgy ,
– weight is a spanning
spanning
tree of G and
is a min T
.
w CTI
¥Tulum) is themin weight
, c. among all Shaff s
.
-Assume ⇒
Invariant : prior to each iteration , A is a subset of
the MSF
invariant holds
. ) is “safe” ifCair)belongstotheMst
Cair)
all edge weights are distinct
MST
I
unique
Assume the
(u n safe
–
An it
edge is
–
⇒
to
add
Definition: A cat IS, VIS) of an undirectedgraph G-(ViE)
of V into two non – empty
” —
sets.
is
a partition
VIS o,
•
. – s- –
.
–
–
.
‘
6
Definition An
( crossing edge)
, Carlc-E crossed the cut CS vis)
• , or
edge if
one endpoint is in S and the other one is in VIS .
§• ÷:÷.
-w
✓ IS
he a
min
–
then, , ever μ
Prout : uppose
(go, e
s”
I M.S. T.
T sit
.
.
e¢
:
a n t i: c : : ” : ” : ‘
‘ m’ t : : : : i :
O
weight
)
. . …ge eye,
w k
)
wee, sweet
⇒’,
t ..
t0and StV
S ‘t
edge
,, any,,n, edgee
,
.
+
,
that crosses the cat CS vis
-w Lt’t=wCTI Ce
i:÷÷:” “mi.
….
w
↳ ,,
TT
Cutpropertytheorem letsc Vs
andlete-
Carl W
(T)
I :L II
mondatnth iy . H s
” MST ”Algorithm
‘.
.
= Au {Cair)} 3
15112J
• •¥%/1o
.
Greedy
7
Ii:÷÷÷÷:÷÷÷÷÷÷÷.
min weight crossing edge for cut
CS VIS) ,
return
.
A A
-kruskali Algorithm
A- = of
while (IAI e Irl-
A – t } Aaf 1,474,77
A — fit
-11,4447kt
+ y
§ ‘
1)do
find !laid of edge
a — A –
that A flin t
limit weight
l
A- =t min
.
sit!!.fm • …
9
I inA . 7 . 6 . ¢
Au luv’t’ 5 71 A←’ Il10 3y
a
i
‘ s
”
t
4.- t
using only edges
return
union•”. if
‘
A Ii 12
P wofofCorretnessCKrusk
adds edge
thate is
le
:! \
e in some iteration
S =L,
. suppose alg.
a
Cz
——–i
C,
suffices
→
I
–
to safe
prove edge
.
.
– – –
.
‘iIl “”
÷at :. iii.
1 l
-: e.moi
” .mn
comment Ci (fi#j)
= U Cj
i’theft .” ‘i :
r
e
2,44 is min weight crossing edge
%
component
Ci
to
,
.
VIS S=C, j-
C,
Cy
.
—
a.
.
—–l
-‘
–
–
Primitgorithm ” start” vertex A= 0←letsbe
while IAI < IVI- I
A- = -13,4, 2,7 , 1,107
edge Curl of min weight that connects isolated vertex
\, .tn?autcuirH return A
"
"
find
9 ..
IZ4
g#
o .t..
10 5
11 3
•* 12
froofofcorrcctnesslpr.im#
some iteration, suppose Prim adds edge Cair)
- suffices to show that luv) is safe IT
= min weight crossing edge for some cut CS, vis)
of vertices that A Spans
( " touched by A) (vertices in the turret
- in
. .
Let s = set
. .
(a w )