Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Streaming Algorithms
Streams Si S Sm
S number
Questions
distinct elementsitem frequenciesheavy hitters
averagemedian
Frequencies Heavy hitters
Find countIX sto x Em EcountME x
Find every item thatappears I 2 Em timesreturn noitemthat appears Emtimes
XI times X appears in stream
AlgorithmSet 5 of item count pairsFor each item Xj C stream
if Xy C is in set increment Celse add Xj 1 to setif ISl K decrementcount foreach itemRemove all itemswithcount 0
Output countyif XES return countelse return 0
Ex K 2
Stream 2 5 7 2 2 5 5 5 5 7 2
is pity I iNote if S is full no need to add delete new item
claim output XI E x
why Increment count for at most c times
claim output1 12 Ix
Why in total court of X incremented xtotal increments m I xwhen count x decremented
K items are decrementedE m total decrementsC Mlk decrements of
Conclusion if output1 1 0 thenIx E Mlk
else if output41 0 thenC Z x E
ChooseK Y
Space 0 E tog m t tog nError Cm
qNole Countevery
bit
Heavy hittersreturn X if count x z 2 EM
Graphisstream of edges
Goal 0 n or Oln polylog Intl space
Connectivityis it connectedconnected components
ALLf forest initiallyfor each edge e
if F U e has no cyclesF FU e
idea maintain spanning forest
check for cycles Union Find
Space Oln log n
MST
Bipartite Graphs
Shortest Paths
Goal answer queries dlunt
Approximation return
dla.ME answers c d n v
TT3 C logn
Ideamaintain subgraph Hno small cycles in It allowed
AlgyH 0for each edge e U V
if d la v 2K 1 in Hadd e to pf
return It
Claim dath ul I da thVIda 4,4 E KK 1 do In v
why Every edge i It is in Gand
Let u x X Xe V beshortest path in G Then eitherXy Xp E H or d Xi XpHE 2k I
TH is a 12k it spanner
How big is It
Every cycle in It is size Z 2kt
t.es
girth 1422kt Isize of minimum cycle
Every graph with girth 72K has
01h edges
Proof Let It be graph with girth 72Kand Z 10 n edges
Repeat until none leftif u EH has degree C 2N thendelete u and adjacent edges
At most 2N n edges deletedI 8h remain
graph not empty
Now It has min degree 2hIt has no cycles E 2K
KEEFE
AhhhFix u in HLet T be all nodes at distance EkT is a tree
Leaves may haveedges between the
nodes 2n n
contradiction
Conclusion The graph we constructhas 0 n l edges
Two extremes
15 2Space 0 n tog m
3 spanner
K log n
Space 0 n logmI O n togmO login spanner
Better
Erdos Girth ConjectureFor KZ 2 n sufficiently large D n nodegraphwith girth 72k and I n Jno better spanner possible
why If It is such a graph andIt CH is spanner any edge inHl H haspath 22K in
It so H is not a 211 1 spanner
Matching
f V E M C E is a matching ifn nodes V eye CM e hem edges
streamingM 0for each edseetu.ir in stream
feuded intimeif U and V not matched in M
add e to M
Claim It is a matchingNever add conflicting edges
et M't max matchingclaim IM'tf E z lmy
M is Yz approximation
PI Let e EM'tIf e EM charge 1 to eElse
F e EM adjacent to e
charge 1 to e
total charges MY
Each e EM is charged E 2one for each endpoint or one for e
To eEM'tteem't
total charges E 21Mt
In IE 21Mt
Weighted Matching
each edge has weight to let
u 10 V
Greedy
to 44144
M 0for eachedge e uit
let C edges U and V in Mif ulet WIC then
M MICm Mule
Does it work
L o eo o o eo o o o
L Max weightmatch 217greedy weight 2not a good approximation
8 pp
J GreedyM 0for eachedge e uit
let C edges U and V in Mif wle Itf WIC then
M MICm Mule
ttt Hr its City Itsootoo o eo o o am.no o_O
Max weight It It8 t t l fn E IRL
zGreedia E Ith in this example1Mt't not in general
Terminologyedge e is borne if whenadded to Medge e killed by E if e removedfrom M when e bornedge e is survivor if bornandnever killed
T e edgeskilled by ET e edgeskilledby E ET e
Tg e edges killed by e ETg le
Tree ofthe Dead T e Tj e
ofa T Cel
f NT let
A Ariesclaim W Tj et It 8 w T let
each edge eu let Its T Ie
ttt w Tle I 8 II V Tle jhile t ult le
u let ultle
sublet cute
ultlells WII
charging Scheme
For each e EM't1 if e E T le't for Survivor e thencharge wle toe
2 if e H Tle then it was never bornwhen e arrived wld E htt U ccase 1 C e I
charge wle to ew let C its w e
case 21 C e e Icharge wle1h to e
u leftwleyCharge Wleth to ez
wle.ltbledNole wle E Its u left Ute
charge to e E Its u letcharge to e E Its U e
Total charge w Mt
Each EE Tle UM is charged E 2 Its Uce2 unborn in MOR f killed in M't
Betterif U v kills e u wand e charged fur unborn h gthen move charge for 4 y to es tu v
movecharge
f sey g EM't
Note Only charge u v for unborn Medges adjacent to U or V
no edge has more than 2 chargesno killed edge has more than I charge
iv then su killed
fo Moves I charge
I w1h41 I 2 Its wcml t its E.mu Tle
C 2 Its Ulm t Its fam
C 2 Its Ulm t WIM
E w m 3 28 t j
choose 8 7 approx0.17
What if more passes
E passes for ITT approx
Let M be stir approx I pass
RepeatMold Mfor eachedge e uit
let C edges U and V in Mif wle Itf WIC then
M MICm Mule
Until wlmwlm.la E l t k
each iteration increases ulmby factor Hk
After l iterations 2 T
ulm't WIN 4M It Kl
l C log 16
fix K later
k01
Let My M after iteration jc unchanged in iteration j
B My h Mg 1
HK w IMAI y
4M
when 4Mt it w by Itu Bgdone 2 wlMI
wlmf.twtulBdZLkmwlMDt8ulBg
SolvefrBjWIMg truly 2 ltHwlM
It 74
WHIZ lt klM211 tk
sumoygif.in
OPT fly 3 2 ulna UNFIT
no tree of dead
2 Its W Bg2 Its f s 28 E p I
Efftst2Dulm Itt U Ba
Ef's 3 2Dump lit ftp JulMD
Set K y
E 2 38 WINDset 8 21
E 2 2 E U ng 2 24 Ulm