Lecture4 GraphStreams
Lecture4 GraphStreams
Lower Bounds
1
Graph Streams
• Fixed vertices 𝑉
2
Graph Streams
• Turnstile model
• 𝜎 = 𝑒1 , 𝑐1 , … 𝑒𝑚 , 𝑐𝑚 where
- 𝑒1 , … , 𝑒𝑚 ∈ 𝑉 × 𝑉,
- 𝑐1 , … , 𝑐𝑚 ∈ {−1, +1}
• Graph: 𝐺 = 𝑉, 𝐸 where 𝐸 = 𝑒 σ 𝑒,𝑐𝑖 ∈𝜎 𝑐𝑖 ≠0
3
Semi-Streaming Algorithms
• Universe size: Θ 𝑛2
• Streaming: space polylog 𝑛
• Semi-streaming: space 𝑂෨ 𝑛 = (𝑂 𝑛 ⋅ polylog 𝑛
4
Graph Problems – Today :
Insert-only streams:
• Unweighted maximum matching
• Weighted maximum matching
Turnstile streams:
• Connectivity
5
Maximum Matching
6
Unweighted Maximum Matching
7
Unweighted Maximum Matching
8
Unweighted Maximum Matching
9
Immediate Lower Bound
• Unweighted maximum matching requires at least
?
bits of memory
10
Greedy Algorithm
• Set 𝑀 ← ∅
• Process 𝑢, 𝑣 :
If both 𝑢, 𝑣 are unmatched in 𝑀,
add 𝑢, 𝑣 to 𝑀.
• Claim: (1/2)-approximation
If 𝑢, 𝑣 ∈ 𝐸 but 𝑢, 𝑣 ∉ 𝑀:
𝑢 or 𝑣 have an edge in 𝑀.
11
Analysis
• Let 𝑀 ∗ be a maximum matching
• For any 𝑢, 𝑣 ∈ 𝑀∗ :
either 𝑢 or 𝑣 are matched in 𝑀.
• For every edge that is not in 𝑀∗ there is an edge in 𝑀
• … so 𝑀 ≥ 𝑀∗ ???
12
Analysis
• Each 𝑢, 𝑣 ∈ 𝑀∗ : “one unit of blame”
• Who to blame?
• Edges in 𝑀
• Want: each 𝑒 ∈ 𝑀 “not blamed too much”
If each 𝑒 ∈ 𝑀
blamed ≤ 𝐵 times:
𝑀 ≥ |𝑀∗ |/𝐵
𝑀∗ 𝑀
Analysis
• Each 𝑢, 𝑣 ∈ 𝑀∗ : “one unit of blame”
𝑢 or 𝑣 (or both) are matched in 𝑀.
If 𝑢 is matched: charge 1 to 𝑢’s edge
Otherwise, charge 1 to 𝑣’s edge.
• Total blame = 𝑀∗
• Each edge 𝑢, 𝑣 ∈ 𝑀 charged at most ?
⇒ 2 𝑀 ≥ total blame
⇒ 𝑀 ≥ |𝑀∗ |/2
Can we Do Better Than ½-Approximation?
15
Can we Do Better Than ½-Approximation?
1 1Τlog log 𝑛
• Better than 1 − requires space Ω 𝑛1+Ω
𝑒
• Much better algorithms known for > 1 pass
16
Weighted Maximum Matching
7
1 2
17
Somewhat-Greedy Algorithm
•𝑀←∅ // Edges+weights
• Process 𝑒 = 𝑢, 𝑣 , 𝑤 𝑒 :
Let 𝐶 = edges touching 𝑢 or 𝑣
If 𝑤 𝑒 > 2𝑤 𝐶 :
𝑀 ← 𝑀∖𝐶 ∪ 𝑒
Else do nothing.
18
Analysis
Life cycle of an edge 𝑒:
• 𝑒 is born when it enters 𝑀
• 𝑒 is killed by 𝑒′ if 𝑒 was removed from 𝑀 because of 𝑒′
• 𝑒 is a survivor if it is born and never killed
19
Example
• 𝑒1 is born
• 𝑒2 is born
7 𝑒2 • 𝑒3 is born; 𝑒1 , 𝑒2 are killed by 𝑒3
1 2
𝑒1 𝑒3
20
Example
20 • 𝑒1 is born
𝑒5
• 𝑒2 is born
10 𝑒2
7 • 𝑒3 is born; 𝑒1 , 𝑒2 are killed by 𝑒3
𝑒4 2 • 𝑒5 is born; 𝑒3 is killed by 𝑒5
1
𝑒1 𝑒3
21
“Trail of the Dead”
20
𝑒5
For a survivor 𝑒 ∈ 𝑀: 10
𝑇 𝑒 = 𝐶1 ∪ 𝐶2 ∪ ⋯, where 7 𝑒2
• 𝐶1 = { edges killed by 𝑒 }, 𝑒4 2
1
• 𝐶2 = { edges killed by edges in 𝐶1 }, 𝑒1 𝑒3
•…
Observation: 𝑤 𝑇 𝑒 ≤ 𝑤 𝑒
Proof: set 𝐶0 = 𝑒 . For each 𝑖 we have 𝑤 𝐶𝑖 ≥ 2𝑤 𝐶𝑖+1 .
1 1
𝑤 𝑇 𝑒 = 𝑤 𝐶𝑖 ≤ 𝑤 𝐶𝑖 = 𝑤 𝑇 𝑒 + 𝑤 𝑒
2 2
𝑖≥1 𝑖≥0 22
Charging Scheme
Charge each 𝑜 ∈ 𝑀∗ to the survivors and their trails of dead: 4
2
• Say 𝑒 ∈ 𝑀 ∪ 𝑇 𝑀 is accountable to 𝑜 if 1
• 𝑒 = 𝑜, or
• 𝑜 was not born because 𝑒 was in 𝑀 when 𝑜 arrived. At most 2 such edges
• Who gets blamed for 𝑜?
• If one edge 𝑒 is accountable to 𝑜: charge 𝑤 𝑜 to 𝑒
• If 𝑒1 , 𝑒2 are accountable to 𝑜: charge
𝑤 𝑒1
⋅ 𝑤 𝑜 to 𝑒1
𝑤 𝑒1 +𝑤 𝑒2
𝑤 𝑒2
⋅ 𝑤 𝑜 to 𝑒2
𝑤 𝑒1 +𝑤 𝑒2
23
Charging Scheme
Charge each 𝑜 ∈ 𝑀∗ to the survivors and their trails of dead: 4
2
• Say 𝑒 ∈ 𝑀 ∪ 𝑇 𝑀 is accountable to 𝑜 if 1
• 𝑒 = 𝑜, or
• 𝑜 was not born because 𝑒 was in 𝑀 when 𝑜 arrived. At most 2 such edges
• Who gets blamed for 𝑜?
• If one edge 𝑒 is accountable to 𝑜: charge 𝑤 𝑜 to 𝑒
• If 𝑒1 , 𝑒2 are accountable to 𝑜: charge
𝑤 𝑒1
Observation: ⋅ 𝑤 𝑜 to 𝑒1
𝑤 𝑒1 +𝑤 𝑒2
Charge by 𝑜 to 𝑒 ≤ 2𝑤 𝑒 . 𝑤 𝑒2
⋅ 𝑤 𝑜 to 𝑒2
𝑤 𝑒1 +𝑤 𝑒2
𝑤 𝑜 ≤ 2 𝑤 𝑒1 + 𝑤 𝑒2 24
So Far:
• Each 𝑜 ∈ 𝑀∗ charges ≤ 2𝑤 𝑒 to each 𝑒 ∈ 𝑀 ∪ 𝑇 𝑀 4
2
• Each 𝑒 ∈ 𝑀 ∪ 𝑇 𝑀 charged by at most 2 edges 1
• Total charge to 𝑒 ∈ 𝑀 ∪ 𝑇 𝑀 ≤ 4𝑤 𝑒
• 𝑤 𝑀 vs. 𝑤(𝑀∗ ) ?
• Recall: 𝑤 𝑇 𝑒 ≤𝑤 𝑒
• Charge to 𝑒 ∈ 𝑀 ≤ 4𝑤 𝑒 + σ𝑒 ′ ∈𝑇 𝑒 4𝑤 𝑒 ′ ≤ 8𝑤 𝑒
⇒ 𝑤 𝑀 ≥ 𝑤(𝑀∗ )/8
25
Conclusion: Maximum Matching
• (1/2)-approximation for unweighted
• Huge open problem
• (1/8)-approximation for weighted
• Actually 1/6 (HW)
26
Step 1: 𝑠-𝑡 Connectivity
• Given 𝑠, 𝑡 ∈ 𝑉 and directed graph 𝐺 = 𝑉, 𝐸 ,
is there a directed path from 𝑠 to 𝑡 ?
• Claim: requires Ω 𝑛2 space
𝑠 𝑡
𝐿 𝑅
𝐿 = 𝑅 =𝑛
27
Step 1: 𝑠-𝑡 Connectivity
• Given 𝑠, 𝑡 ∈ 𝑉 and directed graph 𝐺 = 𝑉, 𝐸 , Must store 𝐸′ exactly
is there a directed path from 𝑠 to 𝑡 ?
• Claim: requires Ω 𝑛2 space
Stream:
1. Edges 𝐸′ ⊆ 𝐿 × 𝑅
How much
memory?
𝑠 𝑡 2. ???
𝐿 𝑅
𝐿 = 𝑅 =𝑛
28
29
30
Connectivity in Turnstile Graph
Streams
31
Connectivity
• In 𝑜 𝑛2 space?
• Seems hard:
Θ 𝑛2 edges Θ 𝑛2 edges
“Uniformly random”*
distinct element
=
*error: 1/𝑛𝑐
33
Reminder: ℓ0 -Sampling
Works in the turnstile model:
• Elements “arrive” and “leave”
• 𝑓𝑖 = (#times 𝑖 arrived) – (#times 𝑖 left)
• Sample from 𝑖 ∶ 𝑓𝑖 ≠ 0
Reminder: ℓ0 -Sampling
Additivity:
sketch of 𝜎1 + 𝜎2 sketch of 𝜎1 + sketch of 𝜎2
𝑀 𝜎1 𝜎2 𝑀 𝜎1 𝑀 𝜎2
× + = × + ×
35
Boruvka’s MST Algorithm
Grow forest:
1. Each component chooses
lightest outgoing edge
36
Boruvka’s MST Algorithm
Grow forest:
1. Each component chooses
lightest outgoing edge
2. Unify components
37
Boruvka’s MST Algorithm
Grow forest:
1. Each component chooses
lightest outgoing edge
2. Unify components
38
Boruvka’s MST Algorithm
Grow forest:
1. Each component chooses
lightest outgoing edge
2. Unify components
3. Repeat
39
Boruvka’s MST Algorithm
Grow forest:
1. Each component chooses
lightest outgoing edge
2. Unify components
3. Repeat
40
Boruvka’s MST Algorithm
#components ← #components/2
Grow forest:
1. Each component chooses
any lightest outgoing edge
2. Unify components
3. Repeat
𝑂 log 𝑛 iterations
41
Implementing Boruvka Using Linear Sketches
• Define 𝑁𝑏𝑟 𝑣 :
𝑁𝑏𝑟 𝑣 𝑢 = 1 ⇔ 𝑢, 𝑣 ∈ 𝐸 2
0 1 𝑣 5
1 2
0 3
0 4 6
1 5
1 6
42
Implementing Boruvka Using Linear Sketches
• For each 𝑣 ∈ 𝑉: 𝑆𝑣 ← ℓ0 -sketch(𝑁𝑏𝑟 𝑣 )
• Sample neighbor 𝑢 ∈ 𝑁𝑏𝑟 𝑣
43
Implementing Boruvka Using Linear Sketches
• For each 𝑣 ∈ 𝑉: 𝑆𝑣 ← ℓ0 -sketch(𝑁𝑏𝑟 𝑣 )
• Sample neighbor 𝑢 ∈ 𝑁𝑏𝑟 𝑣
44
Implementing Boruvka Using Linear Sketches
• For each 𝑣 ∈ 𝑉: 𝑆𝑣 ← ℓ0 -sketch(𝑁𝑏𝑟 𝑣 )
• Sample neighbor 𝑢 ∈ 𝑁𝑏𝑟 𝑣
• Unify along every edge sampled
What now?
45
Idea: Use Additivity
Redefine 𝑁𝑏𝑟 𝑣 :
𝑉
• 𝑁𝑏𝑟 𝑣 : → −1,0, +1
2
𝑁𝑏𝑟 𝑣 𝑥,𝑦 = 0 if 𝑥, 𝑦 ≠ 𝑣
1, 𝑣, 𝑤 ∈ 𝐸 and 𝑣 > 𝑤
𝑁𝑏𝑟 𝑣 𝑣,𝑤 = ቐ−1, 𝑣, 𝑤 ∈ 𝐸 and 𝑣 < 𝑤
0 otherwise
46
1, 𝑣, 𝑤 ∈ 𝐸 and 𝑣 > 𝑤
Idea: Use Additivity 𝑁𝑏𝑟 𝑣 𝑣,𝑤 = ቐ−1,
0
𝑣, 𝑤 ∈ 𝐸 and 𝑣 < 𝑤
otherwise
+1 4
1
-1 2
+1 -1 3
+1
5
𝑵𝒃𝒓(𝟐)
𝑵𝒃𝒓(𝟐) 𝑵𝒃𝒓(𝟑) +𝑵𝒃𝒓(𝟑)
1,2
1,3
2,3
3,4
3,5
47
Implementing Boruvka Using Linear Sketches
• For each 𝑣 ∈ 𝑉: 𝑆𝑣 ← ℓ0 -sketch(𝑁𝑏𝑟 𝑣 ) Using same randomness!
48
Implementing Boruvka Using Linear Sketches
• For each 𝑣 ∈ 𝑉: 𝑆𝑣 ← ℓ0 -sketch(𝑁𝑏𝑟 𝑣 ) Using same randomness!
-1
49
The Algorithm
• Generate random 𝑀 Post-processing:
• Initialize 𝑆𝑣 = 0ത : 𝑣 ∈ 𝑉 •𝑈←𝑉
• Process 𝑢, 𝑣 , 𝑐 : • While 𝑈 > 1:
• If 𝑢 < 𝑣 set 𝑥 ← 𝟙 𝑢,𝑣 • 𝐸 ′ ← sample 𝑆𝑢 ∶ 𝑢 ∈ 𝑈
• If 𝑢 > 𝑣 set 𝑥 ← −𝟙 𝑢,𝑣 • Let 𝐶 ⊆ 2𝑈 be the connected
• 𝑆𝑢 ← 𝑆𝑢 + 𝑀 ⋅ 𝑐𝑥 components of 𝑈, 𝐸 ′
• 𝑆𝑣 ← 𝑆𝑣 + 𝑀 ⋅ −𝑐𝑥 • 𝑈←𝐶
• For each 𝑐 ∈ 𝐶: set
𝑆𝑐 ← 𝑆𝑐
𝑢∈𝑐
50
Things to Worry About
• Success probability = ?
51
Things to Worry About
• Up to Θ 𝑛 components Instead: set 𝛿 = 1/100
• All components must “succeed” Constant fraction of nodes succeed…
⇒ 𝛿 < 1/𝑛
𝑂 log1.5 𝑛 iterations
⇒ pay extra Θ log 𝑛
52
More Things to Worry About
• After unifying 𝑆 𝑢,𝑣 ← 𝑆𝑢 + 𝑆𝑣 , does 𝑆 𝑢,𝑣 “still work”?
• No!
• Queried 𝑆𝑢 , 𝑆𝑣 to decide what to unify
• Randomness in 𝑆 𝑢,𝑣 no longer independent of input!!
Instead:
• Let 𝑇 = #iterations
• Prepare 𝑆𝑢1 , … , 𝑆𝑢𝑇 for each 𝑢 ∈ 𝑉
• Use the 𝑖-th copy for iteration 𝑖
53
The Algorithm
• Generate random 𝑀1 , … , 𝑀𝑇 Post-processing:
• Initialize 𝑆𝑣𝑖 = 0: 𝑣 ∈ 𝑉, 𝑖 ≤ 𝑇 • 𝑈 ← 𝑉, 𝑖 ← 1
• Process 𝑢, 𝑣 , 𝑐 : • While 𝑈 > 1:
• If 𝑢 < 𝑣 set 𝑥 ← 𝟙 𝑢,𝑣 • 𝐸 ′ ← sample 𝑆𝑢𝑖 ∶ 𝑢 ∈ 𝑈
• If 𝑢 > 𝑣 set 𝑥 ← −𝟙 𝑢,𝑣 • Let 𝐶 ⊆ 2𝑈 be the connected
For each 𝑖 = 1, … , 𝑇: components of 𝑈, 𝐸 ′
• 𝑆𝑢𝑖 ← 𝑆𝑢𝑖 + 𝑀𝑖 ⋅ 𝑐𝑥 • 𝑈←𝐶
• 𝑆𝑣𝑖 ← 𝑆𝑣𝑖 + 𝑀𝑖 ⋅ −𝑐𝑥 • For each 𝑐 ∈ 𝐶, 𝑗 = 𝑖 + 1, … , 𝑇: set
𝑗 𝑗
𝑆𝑐 ← 𝑆𝑐
𝑢∈𝑐
54
Connectivity: Summary
• For each 𝑣 ∈ 𝑉: need 𝑂 log 𝑛 copies of ℓ0 -sketch
⇒ space 𝑂 𝑛 log 3 𝑛
• Better than 𝑂 𝑛2 ….
55
Next Class: Lower Bounds
Using one-way communication complexity:
• “One problem to rule them all” (Index)
• Reductions from Connectivity, matching, …
56