Dynamic Graph Algorithms II Surender Baswana Visiting Professor till 31st May 2020 Heinz Nixdorf Institute & Department of Computer Science (Algorithms and Complexity Group) sbaswana@campus.uni-paderborn.de sbaswana@gmail.com
Fully dynamic connectivity Update time Query time Reference O( 𝒎 ) O(𝟏) Frederickson, SICOMP 83 O( 𝒏 ) O(𝟏) Eppstein et al. J. ACM 91 expected amortized randomized O( log 𝟑 𝒏) O(log 𝒏) Henzinger and King, J.ACM 99 Prerequisites ? Elementary knowledge of probability
Deterministic Algorithm Input Output The output as well as the running time are functions only of the input. Algorithm
Deterministic Algorithm Randomized Random bits Input Output The output or the running time are functions of the input and random bits chosen . Algorithm
Organization of the Talk 𝟏. Random sampling 𝟐. Experiencing the difficulty of the problem 𝟑. A simple but inefficient algorithm 𝟒. Designing the efficient algorithm
Part I Random Sampling A gentle introduction
Elementary Probability Tossing a coin 𝟏 𝟐 𝒌 𝐏[ No HEAD appears in 𝒌 tosses] = ?
Problem: Given an array A[1…𝑛] storing 0/1s. Report any index storing 𝟏. Theorem: For every deterministic algorithm, there exists an input for which 𝛀(𝑛) entries will be scanned to find the first 𝟏. At least ½ of the entries in A are 𝟏. A 𝟎 𝟎 𝟏 𝟎 𝟎
Random Sampling Problem: Given an array A[1…𝑛] storing 0/1s. Report any index storing 𝟏. At least ½ of the entries in A are 𝟏. 1 𝑘 A 𝟎 𝟏 Randomized Algorithm count 𝟎; Repeat count count +𝟏; 𝒊 a random number from [𝟏..𝒏]; Until ((A[𝒊] ≠𝟏) and (count < 𝒄 log 𝒏)) 𝒌 𝟏 𝟐 𝒄log 𝒏 𝟏 𝒏 𝒄 Probability of failure :
Experiencing the difficulty of the problem Part II Experiencing the difficulty of the problem
Fully dynamic connectivity
Fully dynamic connectivity Update time Query time Reference O( 𝒎 ) O(𝟏) Frederickson, SICOMP 83 O( 𝒏 ) O(𝟏) Eppstein et al. J. ACM 91 expected amortized randomized O( log 𝟑 𝒏) O(log 𝒏) Henzinger and King, J.ACM 99 1 2 1 2 3 2 log 𝒏 O( 𝒎 log 𝟐 𝒏) O( 𝒌 𝒎 log 𝟐 𝒏) 𝒌 levels
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time The 2-level algorithm 2 1
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time Idea: Maintain a spanning forest
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time Decremental What is the real challenge ?
A simple but inefficient algorithm Part III A simple but inefficient algorithm
A simple decremental algorithm Question: Can we find a replacement edge in 𝑶 (| 𝝁(𝑻) |) time ? Operations Time Enumerating all non-tree edges incident on a tree 𝑻 O(𝝁(𝑻)log 𝒏) Checking if two vertices belong to the same tree O(log 𝒏) 𝝁(𝑻) : non tree edges 𝑻
A simple decremental algorithm Question: Can we find a replacement edge in 𝑶 (| 𝝁(𝑻) |) time ? Euler Tour tree 𝝁(𝑻) : non tree edges 𝑻 Homework: Picking a non-tree edge randomly uniformly in O(log 𝒏) time ?
The efficient algorithm Part IV The efficient algorithm
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time Decremental A combination of two simple tools A simple 𝑶 (| 𝝁(𝑻) |) time algorithm Random sampling Exercise
1 |cut( 𝑻 𝟏 , 𝑻 𝟐 )| |𝝁( 𝑻 𝟏 )| ≥ 𝟏 𝒌 < 𝟏 𝑘 sparse dense Data structure for 𝑻 𝟏 ≥ 𝟏 𝒌 < 𝟏 𝑘 sparse dense 1 Pick non tree edge incident on 𝑻 𝟏 𝑘 log 𝑛 uniformly randomly 𝑻 𝟏 𝑻 𝟐 𝑻 cut( 𝑻 𝟏 , 𝑻 𝟐 )
Trivial algorithm at Level 𝟐 What if the cut is sparse ? |𝝁( 𝑻 𝟏 )| < 𝟏 𝒌 sparse Trivial algorithm at Level 𝟐 What if the cut is sparse ? Level 𝟐 Level 𝟏 𝑻 𝟏 𝑻 𝟐 Random sampling at level 𝟏
Handling the deletion of a tree edge 2-Level approach A partition of 𝑬 into two levels : ( 𝑬 𝟏 , 𝑬 𝟐 ) In the beginning, 𝑭 𝟏 : spanning forest of 𝑬 𝟏 𝑭 𝟐 : spanning forest of 𝑬, 𝑬 𝟏 =𝑬 and 𝑬 𝟐 = Ø 𝑭 𝟏 ⊆ 𝑭 𝟐
Algorithm for Deletion of tree edge (𝒖,𝒗) yes (𝒖,𝒗) ϵ 𝑭 𝟐 \ 𝑭 𝟏 ? scan 𝝁 𝟐 Level 𝟐 No 𝑻 𝟏 : smaller tree Sample(𝝁( 𝑻 𝟏 )) 𝒆 yes 𝒆 ∈ cut( 𝑻 𝟏 , 𝑻 𝟐 ) ? Join 𝑻 𝟏 and 𝑻 𝟐 at Level 1 No yes Level 𝟏 counter++ <𝒄𝒌 log 𝒏 ? No Compute cut( 𝑻 𝟏 , 𝑻 𝟐 ) No Probability ≤𝒏 −𝒄 Is cut( 𝑻 𝟏 , 𝑻 𝟐 ) sparse ? yes Move cut( 𝑻 𝟏 , 𝑻 𝟐 ) to Level 2 Add an edge from cut( 𝑻 𝟏 , 𝑻 𝟐 ) to 𝑭 𝟐
Analysis ≤ |𝝁( 𝑻 𝟏 )| 𝒌 charge 𝒅𝒆𝒈(𝒗) 𝒌 edges to each 𝒗 ∈𝑻 𝟏 Upon splitting 𝑻 into 𝑻 𝟏 and 𝑻 𝟐 , how many edges are passed to level 2 ? ≤ |𝝁( 𝑻 𝟏 )| 𝒌 charge 𝒅𝒆𝒈(𝒗) 𝒌 edges to each 𝒗 ∈𝑻 𝟏 | 𝝁 𝟐 | = O( 𝑚 𝑘 log 𝑛) Level 𝟐 Level 𝟏 𝒗 𝑻 𝟏 𝑻 𝟐
Analysis Theorem: Decrement connectivity can be maintained in expected amortized 𝐎( 𝒎 log 2 𝒏 ) time per edge deletion. Cases Time taken (𝒖,𝒗) ϵ 𝑭 𝟐 \ 𝑭 𝟏 O( 𝒎 𝒌 log 2 𝒏) (𝒖,𝒗) ϵ 𝑭 𝟏 O(𝒌 log 2 𝒏) + O(𝝁( 𝑇 1 ) log 𝒏) ×𝒏 −𝒄
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time Add every newly inserted edge to level 𝟐. Periodically rebuild the data structure after every 𝒎 insertions. Expected amortized time per update : O( 𝒎 log 𝒏) Theorem: Fully dynamic connectivity can be maintained in expected amortized 𝐎( 𝒎 log 𝒏 ) time per update.
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time The 2-level algorithm Trivial algorithm at Level 𝟐 𝟐 𝟏 Random sampling at level 𝟏 Reduce the sampling rate
Fully dynamic connectivity with O( 𝒎 lo g 𝟐 𝒏) update time The 3-level algorithm Trivial algorithm at Level 𝟑 𝟑 Trivial algorithm at Level 𝟐 Random sampling at level 𝟐 𝟐 𝟏 Random sampling at level 𝟏 Homework 𝒌 levels O( 𝒌 𝒎 log 𝟐 𝒏)
Minimum spanning tree Single source shortest paths tree An open problem Minimum spanning tree Single source shortest paths tree A tree that minimizes the “average” stretch for all pairs.
An open problem 𝑑𝑖𝑠 𝑡 𝑇 (𝑢,𝑣) = distance between 𝑢 and 𝑣 in tree 𝑇. 𝑆𝑡𝑟𝑒𝑡𝑐 ℎ 𝑇 (𝑢,𝑣) = A𝑣𝑒𝑟𝑎𝑔𝑒𝑆𝑡𝑟𝑒𝑡𝑐ℎ(𝑇) = There exists an O(𝑚 polylog 𝑛) time algorithm to compute a spanning tree with average stretch (polylog 𝑛). https://link.springer.com/referenceworkentry/10.1007%2F978-0-387-30162-4_215 Can we maintain such a tree efficiently dynamically ? 𝑑𝑖𝑠 𝑡 𝑇 𝑢,𝑣 𝑑𝑖𝑠 𝑡 𝐺 𝑢,𝑣 1 |𝐸| 𝑢,𝑣 ∈𝐸 𝑆𝑡𝑟𝑒𝑡𝑐 ℎ 𝑇 (𝑢,𝑣)