Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano!...

167
Dynamic Graph Algorithms Giuseppe F. Italiano University of Rome Tor Vergata[email protected] http://www.disp.uniroma2.it/users/italiano

Transcript of Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano!...

Page 1: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graph Algorithms

Giuseppe F. Italiano

University of Rome “Tor Vergata”

[email protected] http://www.disp.uniroma2.it/users/italiano

Page 2: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Outline

Dynamic Graph Problems

Methodology & State of the Art

Algorithmic Techniques & Experiments

Conclusions

Page 3: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Outline

Dynamic Graph Problems

Methodology & State of the Art

Algorithmic Techniques & Experiments

Conclusions

Page 4: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Graphs…

Graphs have been used for centuries to model relationships…

1736

Page 5: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Da Demetrescu et al. McGraw Hill 2004

5

Page 6: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Da Demetrescu et al. McGraw Hill 2004

6

Page 7: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Da Demetrescu et al. McGraw Hill 2004

7

Page 8: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Da Demetrescu et al. McGraw Hill 2004

8

Graphs…

Page 9: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Da Demetrescu et al. McGraw Hill 2004

9

Graphs…

Page 10: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graphs

Sometimes, life looks a bit more dynamic …

Page 11: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graphs

Graphs subject to update operations

Insert(u,v)!Delete(u,v)!

SetWeight(u,v,w)!Typical updates:

Page 12: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

A graph

Initialize

Insert Delete

Query

Dynamic Graphs

Page 13: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graphs

Partially dynamic problems Graphs subject to insertions only, ordeletions only, but not both.

Fully dynamic problems Graphs subject to intermixed sequences of insertions and deletions.

Page 14: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graph Problems

Support query operations about certain properties on a dynamic graph

Dynamic Connectivity (undirected graph G) Connected(): Connected(x,y): !Is G connected? Are x and y connected in G?

Dynamic Transitive Closure (directed graph G) Reachable(x,y): Is y reachable from x in G?

Page 15: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graph Problems

Dynamic All Pairs Shortest Paths Distance(x,y):

What is the distance from x to y in G? ShortestPath(x,y):

What is the shortest path from x to y in G?

Dynamic Minimum Spanning Tree (undirected graph G)

Any property on a MST of G

Page 16: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graph Problems

Dynamic Min CutMinCut(): Cut(x,y): Min cut? Are x and y on the same side of a

min cut of G?

Dynamic Planarity Testing planar():

Is G planar?

Dynamic k-connectivity k-connected(): k-connected(x,y): Is G k-connected? Are x and y k-connected?

Page 17: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Graph Algorithms

The goal of a dynamic graph algorithm is to support query and update operations as quickly as possible.

We will sometimes use amortized analysis: Total worst-case time over sequence of ops

# operations

Notation: G = (V,E) n = |V| m = |E|

Page 18: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Amortized Analysis

Example: Counting in Binary Cost is # bit flips

Total cost to count to n?

Worst-case cost to add 1: log(n + 1) + 1 011111…111 100000…000

Total cost to count to n: n logn ?

Page 19: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Amortized Analysis

Amortize: To liquidate a debt by installment payments

Etymology from Vulgar Latin “admortire”: To kill, to reduce to the point of death

In analysis of algorithms, analyze execution cost of algorithms over a sequence of operations I.e., pay for the total cost of a sequence of operations by charging each operation an equal (or appropriate) amount

Page 20: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Amortized Analysis

Example: Counting in Binary Cost is # bit flips

Bit x0 flips n times Bit x1 flips n/2 times Bit x2 flips n/4 times …

Total # bit flips to count to n is ≤ 2n

Amortized # bit flips at each step is ≤ 2

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 …

Page 21: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Amortized Analysis

Another example: Array doubling Dynamic array: double size each time fills up

Array reallocation may require an insertion to cost O(n)

However, sequence of n insertions can always be completed in O(n) time, since rest of insertions done in constant time

Amortized time per operation is therefore O(n) / n = O(1).

Page 22: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Running Example: Fully Dynamic APSP

Given a weighted directed graph G = (V,E,w),perform any intermixed sequence of the following operations:

return distance from x to y (or shortest path from x to y) Query(x,y):

update cost of edge (u,v) to w Update(u,v,w): update edges incident to v [w( )] Update(v,w):

Page 23: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Some Terminology

APSP: All Pairs Shortest Paths

NAPSP, NSSP, NSSS: Shortest Paths on Non-negative weight graphs

SSSS: Single Source Single Sink Shortest Paths

SSSP: Single Source Shortest Paths

Page 24: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Outline

Dynamic Graph Problems

Methodology & State of the Art

Algorithmic Techniques & Experiments

Conclusions

Page 25: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Methodology: Algorithm Engineering

In theory, theory and practice are

the same.

Theory

Page 26: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Why Algorithm Engineering?

The real world out there...

In practice, theory and practice are different…

Page 27: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Programs are first class citizens as well

int, float, double Number types: N, R Only asymptotics matter Seconds do matter Abstract algorithm description Non-trivial implementation

decisions, error-prone Unbounded memory, unit access cost Memory hierarchy / bandwidth Elementary operations take constant time

Multicore CPUs, Instruction pipelining, …

Theory Practice

Page 28: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Bridging the Gap between Theory & Practice

Wish to combine theory and practice…

Theory is when we know

something, but it doesn't work.

Practice is when something works,

but we don't know why.

…i.e., nothing works and we

don't know why.

Page 29: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

The Algorithm Engineering cycle

Algorithm implementation

Experimental analysis

Theoretical analysis Bottlenecks, Heuristics

Deeper insights

More realistic models

Hints to refine analysis

Algorithm design

Page 30: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Algorithm Engineering

Source: www.algorithm-engineering.de

Page 31: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

New models of computation (Ladner et al, cache-aware analyses)

Huge speedups in scientific applications (Anderson, Bader, Moret & Warnow, Arge et al.)

Algorithms and data structures for specific classes (Johnson et al,

TSP; DIMACS Challenges)

New algorithms for shortest paths(Goldberg / Sanders )

New conjectures, new theorems, new

insights (Walsh & Gent Satisfiability, Bentley et al., Bin

packing)

Few Success Stories

Algorithmic Libraries (LEDA / CGAL,

Mehlhorn et al….)

Bast, Funke, Sanders, & Schultes. Fast routing in road networks with transit nodes. Science, 316:566, 2007.

Page 32: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Further Readings

Algorithm Engineering issues:

Bernard Moret: “Towards a Discipline of Experimental Algorithmics”

Richard Anderson: “The role of experiment in the theory of algorithms”

David Johnson: “A theoretician's guide to the experimental analysis of algorithms”

5th DIMACS Challenge Workshop: Experimental Methodology Day.

Catherine McGeoch: “A Guide to Experimental Algorithmics”. Cambridge University Press

Page 33: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Outline

Dynamic Graph Problems

Methodology & State of the Art

Algorithmic Techniques & Experiments

Conclusions

Page 34: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Fully Dynamic APSP

Given a weighted directed graph G = (V,E,w),perform any intermixed sequence of the following operations:

return distance from x to y (or shortest path from x to y) Query(x,y):

update cost of edge (u,v) to w Update(u,v,w): update edges incident to v [w( )] Update(v,w):

Page 35: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Simple-minded Approaches

Keep the solution up to date.

Fast query approach

Rebuild it from scratch at each update.

Do nothing on graph.

Fast update approach

Visit graph to answer queries.

Page 36: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic All-Pairs Shortest Paths

Rebuild the distance matrix from scratch after each

update.

Fast query approach

O(n2)

To answer a query about (x,y), perform a

single-source computation from x.

Fast update approach

O(1) O(1)

Query

Update O(1)

O(1)

Query O(n2)

O(n3)

Update

Page 37: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

State of the Art First fully dynamic algorithms date back to the 60’s

Until 1999, none of them was better in the worst case than recomputing APSP from scratch (~ cubic time!)

Query Update Graph Weight

Ramalin.&Reps 96 general real O(n3) O(1)

King 99 general [0,C] O(n2.5 (C log n)0.5) O(1)

•  P. Loubal, A network evaluation procedure, Highway Research Record 205, 96-109, 1967.

•  J. Murchland, The effect of increasing or decreasing the length of a single arc on all shortest distances in a graph, TR LBS-TNT-26, Transport Network Theory Unit, London Business School, 1967.

•  V. Rodionov, A dynamization of the all-pairs least cost problem, USSR Comput. Math. And Math. Phys. 8, 233-277, 1968.

•  …

Page 38: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Fully Dynamic APSP Edge insertions (edge cost decreases)

Quite easy: O(n2)

10

10

10

10

For each pair x,y check whether D(x,i) + w(i,j) + D(j,y) < D(x,y)

x y

i j

Page 39: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Fully Dynamic APSP

•  Edge deletions (edge cost increases) Seem the hard operations. Intuition:

•  When edge (shortest path) deleted: need info about second shortest path? (3rd, 4th, …)

G … … 0 G

Page 40: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic APSP

O(1) O(1)

Query

O(n2)

O(n2) O(n3) Update

O(n2.5) ~ ~

Demetrescu-I, J.ACM’04 Real-weighted digraphs

King, FOCS’99 Unweighted digraphs

Thorup, SWAT’04Supporting negative weights +improvements on log factors

Decremental bounds: Baswana, Hariharan, Sen J.Algs’07 Approximate dynamic APSP: Roditty, Zwick FOCS’04

~

Page 41: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Quadratic Update Time Barrier?

Θ(n) Θ(n) +1 -1 +1

If distances are to be maintained explicitly, any algorithm must pay Ω(n2) per update…

Page 42: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Related Problems Dynamic Transitive Closure (directed graph G) update query authors O(n2 log n) O(1) King, FOCS’99

Demetrescu-I., Algorithmica’08

O(n1.575) O(n0.575) Demetrescu-I., J.ACM’05

notes

DAGs

Sankowski, FOCS’04

DAGs O(n2) O(1) King-Sagert, JCSS ‘02

Decremental bounds: Baswana, Hariharan, Sen, J.Algs.’07

O(m n1/2) O(n1/2) Roditty, Zwick, SIAM J. Comp.’08 O(m+n log n) O(n) Roditty, Zwick, FOCS’04

Sankowski, FOCS’04 worst-case

Page 43: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Other Problems Dynamic Connectivity (undirected graph G)

update query authors O(log3 n) O(log n/log log n) Henzinger, King,

J. ACM ‘99 (randomized)

O(log2 n) O(log n/log log n) Holm, de Lichtenberg, Thorup, J.ACM’01

Lower bounds: Ω(log n) update Patrascu & Demaine, SIAM J.Comp’06 Ω((log n / log log n)2) update Patrascu & Tarnita, TCS’07

O(n1/3 log n) O(1) Henzinger, King, SIAM J. Comp.’01

Page 44: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Outline

Dynamic Graph Problems

Methodology & State of the Art

Algorithmic Techniques & Experiments

Conclusions

Page 45: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Algorithmic Techniques Will focus on techniques for path problems. Running examples: shortest paths/transitive closure

Page 46: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Locally-defined path properties

Output bounded

Counting

Path decompositions

Algebraic techniques

Page 47: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic shortest paths: roadmap

Shortest path trees

NSSSP Ramalingam-Reps ’96

Decremental BFS Even-Shiloach ’81

Long paths decomposition

NAPSP King ’99

Locally-defined path properties

NAPSP/APSP Demetrescu-Italiano ’04

Reduced costs

SSSP Frigioni et al ’98Demetrescu ’01

Page 48: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Locally-defined path properties

Output bounded

Counting

Path decompositions

Algebraic techniques

Page 49: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic shortest paths: roadmap

Shortest path trees

NSSSP Ramalingam-Reps ’96

Page 50: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Fully Dynamic SSSP

Perform intermixed sequence of operations:

s ∈ V source node

G = (V,E,w) weighted directed graph Let:

Increase(u,v,ε): Increase weight w(u,v) by ε!

Decrease(u,v,ε):!Decrease weight w(u,v) by ε!

Query(v): Return distance (or sh. path)from s to v in G!

w(u,v) weight of edge (u,v)

Page 51: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Ramalingam & Reps’ approach

Maintain a shortest paths tree throughoutthe sequence of updates

Querying a shortest paths or distance takes optimal time

Update operations work only on the portion oftree affected by the update

Each update may take, in the worst case, as long as a static SSSP computation!

But very efficient in practice

Page 52: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Increase(u,v,ε)

v

T(v) T(s)

s

u +ε

Shortest paths tree before the update

Page 53: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

v

w

T'(v) T'(s)

+

s

u

Increase(u,v,ε)

Shortest paths tree after the update

Page 54: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Graph G

Ramalingam & Reps’ approach

u

v

s

s Perform SSSP only on the subgraph and source s

Subgraph induced by vertices in T(v)

Page 55: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Locally-defined path properties

Output bounded

Counting

Path decompositions

Algebraic techniques

Page 56: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Path Counting [King/Sagert, JCSS’02]

C[u,x] C[y,v]

C[u,v]

u x y v

Dynamic Transitive Closure in a DAG Idea: count # distinct paths for any vertex pair

Problem: counters as large as 2n Solution: use arithmetic modulo a random prime

C[u,v] ← C[u,v] + C[u,x] · C[y,v] ∀ u,v: O(n2) C[u,v] ← C[u,v] - C[u,x] · C[y,v] ∀ u,v: O(n2)

Page 57: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Arithmetic mod primes

Reduce wordsize to 2c log n: pick random prime p between nc and nc+1 and perform arithmetic mod p

O(1) time with wordsize O(log n) But false 0s (x mod p = 0 but x ≠ 0)

Lemma. If O(nk) arithmetic computations involving numbers ≤ 2n are performed mod random p of value Θ(nc), then probability of false 0 is O(1/nc-k-1)

(As # ops with particular prime increases, so does chance of getting false 0s)

Page 58: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Arithmetic mod primes Lemma. If O(nk) arithmetic computations involving numbers ≤ 2n are performed mod random p of value Θ(nc), then probability of false 0 is O(1/nc-k-1)

Proof. Let x ≤ 2n. There are O(n / log n) prime divisors of value Θ(nc) which divide x. So, there are O(nk+1/ log n) prime divisors of any of the numbers generated. By Prime Number Theorem, approx. Θ(nc / log n) primes of value Θ(nc). Hence probability that random prime of value Θ(nc) divides any of the numbers generated is O(1/nc-k-1).

Page 59: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Arithmetic mod primes

Reduce wordsize to 2c log n: pick random prime p between nc and nc+1 and perform arithmetic mod p

O(1) time with wordsize O(log n) But false 0s (x mod p = 0 but x ≠ 0)

Lemma. If O(nk) arithmetic computations involving numbers ≤ 2n are performed mod random p of value Θ(nc), then probability of false 0 is O(1/nc-k-1)

Choose new prime every n updates and reinitialize all data structures (k = 3, thus enough c ≥ 5)

Page 60: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Transitive Closure [King/Sagert, JCSS’02]

O(n2) worst-case time O(1) worst-case time Query:

Update:

Works for directed acyclic graphs. Randomized, one-sided error.

Can we trade off query time for update time?

Page 61: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Looking from the matrix viewpoint

C[u,x] C[y,v]

C[u,v]

u x y v

C[u,v] ← C[u,v] + C[u,x] · C[y,v] ∀ u,v:

+ ← ·

Page 62: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Maintaining dynamic integer matrices

Given a matrix M of integers, perform any intermixed sequence of the following operations:

+ ← ·

Update(J,I): M ← M + J · I

Query(i,j): return M[i,j]

O(n2)

O(1)

Page 63: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Maintaining dynamic integer matrices

Lazy approach: buffer at most nε updates Global rebuilding every nε updates Rebuilding done via matrix multiplication

How can we trade off operations?

Page 64: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Maintaining dynamic integer matrices

m

M

m

i1 I1

j1

J1

+ j1· i1 i2 I2

j2

J2

+ j2· i2

i3 I3

j3

J3

+ j3· i3

Page 65: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Maintaining dynamic integer matrices

i1 I1

j1

J1

+ j1· i1

i2 I2

j2

J2

+ j2· i2

i3 I3

j3

J3

+ j3· i3

m

M

m

· M’

+

nε n

Global rebuilding every nε updates

O(nω(1,ε,1))

Page 66: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Back to Dynamic Transitive Closure

C[u,x] C[y,v]

C[u,v]

u x y v

C[u,v] ← C[u,v] + C[u,x] · C[y,v] ∀ u,v:

+ ← ·

Page 67: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Query Time

i1 I1

j1

J1

+ j1· i1

i2 I2

j2

J2

+ j2· i2

i3 I3

j3

J3

+ j3· i3

m

M

m

· M’

+

nε n

O(nε) Total Query time

Page 68: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Update Time

O(n1+ε ) Time:

C[u,v] ← C[u,v] + C[u,x] · C[y,v] ∀ u,v:

+ ← ·

1. Compute C[u,x] and C[y,v] for any u,v

Carried out via O(n) queries

Page 69: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Update Time

O( nω(1,ε,1) / n ε ) Amortized time:

2. Global rebuild every nε updates

Carried out via (rectangular) matrix multipl.

i1 I1

j1

J1

i2 I2

j2

J2

i3 I3

j3

J3

m M

·

M’

+

nε n

Page 70: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Transitive Closure [Demetrescu-I., J.ACM05]

O(nω(1,ε,1)-ε ) O(nε)

for any 0 < ε < 1 Query: Update: +n1+ε

Find ε such that ω(1,ε,1) = 1+2ε

Best bound for rectangular matrix multiplication [Huang/Pan98]

ε < 0.575 O(n1.575) worst-case time O(n0.575) worst-case time Query:

Update:

Page 71: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Locally-defined path properties

Output bounded

Counting

Path decompositions

Algebraic techniques

Page 72: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic shortest paths: roadmap

Shortest path trees

Reduced costs

NSSSP Ramalingam-Reps ’96

Decremental BFS Even-Shiloach ’81

SSSP Frigioni et al ’98Demetrescu ’01

Page 73: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Decremental BFS [Even-Shiloach, JACM’81]

Maintain BFS levels under deletion of edges

dept

h d

Undirected graphs: non BFS-tree edges can be

either between two consecutive levels

or at the same level

Page 74: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Decremental BFS [Even-Shiloach, JACM’81]

Page 75: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Decremental BFS [Even-Shiloach, JACM’81]

This implies that during deletion of edges

dept

h d

each non-tree edge can fall down at most 2d times overall…

O(md) total timeover any sequence

O(d) time per deletion (amortized over Ω(m) deletions)

Page 76: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Can we do better than O(mn)?

Roditty and Zwick [2011] have shown two reductions:

Boolean matrix multiplication

(off-line) decremental undirected BFS

Weighted (static) undirected APSP

(off-line) decremental undirected SSSP

Page 77: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Matrix mult. Decremental BFS

A and B Boolean matrices Wish to compute C=A·B C[x,y]=1 iff there is z such that A[x,z]=1 and B[z,y]=1

A

Bipartite graph with an edge (x,y) for

each A[x,y]=1

B

Bipartite graph with an edge (x,y) for

each B[x,y]=1

C[x,y]=1 iff path of length 2between x on first layer and y on last layer

x

y

Page 78: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

C

Matrix mult. Decremental BFS

A B s 1 0 1 0 0

First row: C[1,x]=1 iff dist(s,x)=3

0 1 0 0 0

Second row: C[2,x]=1 iff dist(s,x)=4

0 0 0 0 0

Third row: C[3,x]=1 iff dist(s,x)=5

0 0 0 0 0 1 0 1 0 0

… …

n deletions and n2 queries Decremental BFS in o(mn) total time would imply Boolean matrix multiplication in o(mn)

x x x

Page 79: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

More details in

Decremental BFS: [Even-Shiloach’81] S. Even and Y. Shiloach, An On-line Edge Deletion Problem, J. Assoc. Comput. Mach, Vol. 28, pp. 1-4, 1981

Reductions to decremental BFS:[Roditty-Zwick’11] Liam Roditty, Uri Zwick, On dynamic shortest paths problems Algorithmica 61(2): 389-401 (2011).

Page 80: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Path decompositions

Locally-defined path properties

Output bounded

Counting

Algebraic techniques

Page 81: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic shortest paths: roadmap

Shortest path trees

Reduced costs

NSSSP Ramalingam-Reps ’96

Decremental BFS Even-Shiloach ’81

Long paths decomposition

NAPSP King ’99

SSSP Frigioni et al ’98Demetrescu ’01

Page 82: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

d

d v

IN(v) maintained as a decremental BFS tree

OUT(v) maintained as a decremental BFS tree

Building block: pair of IN/OUT trees

keeps track of all paths of length ≤ 4 passing through v

x

y

keeps track of all paths of length ≤ d passing through v

Make decremental fully dynamic

For each vertex v:

Page 83: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

v

IN(v)

OUT(v)

x

y

Total cost for rebuilding IN, OUT trees + deleting edges in between: O(md)

This is charged to insert(v)

v

IN(v)

OUT(v)

insert(v) insert(v)

Rebuild IN(v), OUT(v) Rebuild IN(v), OUT(v)

sequence of ops

Make decremental fully dynamic

deletions only for IN(v), OUT(v)

Page 84: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

d=2

d=2 v

IN(v) maintained as a decremental BFS tree

OUT(v) maintained as a decremental BFS tree

Building block: pair of IN/OUT trees

keeps track of all paths of length ≤ 4 passing through v

Doubling decomposition +

x

y

keeps track of all paths of length ≤ 2 passing through v

Decremental BFS Ingredients:

Total cost for building the two trees + deleting all edges: O(m)

Dynamic Transitive Closure [King, FOCS’99]

Page 85: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Doubling Decomposition [folklore]

log n

Xn-1

Transitive closure can be computed with O(log n) products of Boolean matrices

X = adjacency matrix + I Xn-1 = transitive closure

X X paths with ≤ 2 edges

X2 X2 paths with ≤ 4 edges

X4 X4 paths with ≤ 8 edges

Page 86: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

G3

Glog n

… … … … … … …

G0 = G

G1

If there is a pathfrom x to y in G of length ≤ k, thenthere is an edge(x,y) in G⎡log k⎤

Invariant: G2

(x,y) ∈ G2 iff x ∈ IN(v) andy ∈ OUT(v) forsome v in G1

IN/OUT trees in G1 for each vertex

(x,y) ∈ G1 iff x ∈ IN(v) andy ∈ OUT(v) forsome v in G0

IN/OUT trees in G0 for each vertex

Reachability queries in G⎡log n⎤

Dynamic Transitive Closure [King, FOCS’99]

Page 87: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

… … … … … …

G0 = G

G3

Glog n

G1

G2 Edge deletions

(amortized against the creation of trees)

Deletion of any subset of the edges of G

Dynamic Transitive Closure [King, FOCS’99]

Page 88: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

G0 = G

… … … … …

G3

Glog n

G1

G2

IN(v) and OUT(v) rebuilt fromscratch oneach level…

Each level has O(n2) edges

O(n2 log n)total time

Insertion of edges incident to a vertex v

v

v

v

v

v

v

v

v

Dynamic Transitive Closure [King, FOCS’99]

Page 89: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic Transitive Closure [King, FOCS’99]

Correctness? G0 = G

… … … … …

G3

Glog n

G1

G2

Insertion of edges incident to a vertex v

a b c …

v

v

v

v

v

v

v

v

Path a,b,c in Gi-1 ⇒ (a,c) in Gi ?

Page 90: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Path decompositions

Locally-defined path properties

Output bounded

Counting

Algebraic techniques

Page 91: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

A real-life problem

“Road”

Page 92: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

A real-life problem

Highway

Roads

Roads

Page 93: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Are there roads and highways in graphs?

Let P be a path of length at least k.

Let S be a random subset of vertices of size (c n ln n) / k.

Then with high probability P ∩ S ≠ ∅.

Probability ≥ 1 – (1 / nc) ( depends on c )

Long Paths Property [Ullman-Yannakakis‘91]

Page 94: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Select each element independently with probability

n

k

The probability that a given set of k elements

is not hit is

ln1(1 )k

k cc n nkp −⎛ ⎞= − <⎜ ⎟

⎝ ⎠−

lnc npk

=

Long Paths Property [Ullman-Yannakakis‘91]

Page 95: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Long Paths Property

Can prove stronger property:

Let P be a path of length at least k.

Let S be a random subset of vertices of size (c n ln n) / k.

Then with high probability there is no subpath of P of length k with no vertices in S (P ∩ S ≠ ∅ ).

Probability ≥ 1 – (1 / nα c ) for some α > 0.

Page 96: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Exploit Long Paths Property

Randomly pick a set S of vertices in the graph

|S| = c n log n

k c, k > 0

Then on any path in the graph every k vertices there is a vertex in S,

with probability ≥ 1 – ( 1 / nα c )

<k <k <k <k <k <k <k

Rome Palmse vertices in S

Page 97: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Roads and Highways in Graphs

Highway = shortest path between two vertices in S

Highway

Highway entry points = vertices in S

Rome Palmse

Road = shortest path using at most k edges

<k

Road

<k

Road Road

<k

Page 98: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Computing Shortest Paths 1/3

Rome Palmse

k

Compute roads (shortest paths using at most k edges) 1

Even & Shiloach BFS trees may become handy…

Page 99: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Computing Shortest Paths 2/3

…essentially an all pairs shortest paths computation on a contracted graph with vertex set S, and edge set = roads

Highway

<k

Road

<k

Road

Compute highways (by stitching together roads) 2

Page 100: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Computing Shortest Paths 3/3

Highway Rome Palmse

Road Road

Compute shortest paths (longer than k edges)(by stitching together roads + highways + roads) 3

Used (for dynamic graphs) by King [FOCS’99], Demetrescu-I. [JCSS’06], Roditty-Zwick [FOCS’04], …

Page 101: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Fully Dynamic APSP

Given a weighted directed graph G=(V,E,w),perform any intermixed sequence of the following operations:

return distance from x to y (or shortest path from x to y) Query(x,y):

update weight of edge (u,v) to w Update(u,v,w):

Page 102: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

King’s algorithm [King’99] Directed graphs with integer edge weights in [0,C]

O(1) query time O(n2.5 √C) space O(n2.5√C) update time ~ ~

1.  Maintain dynamically shortest paths up to length k = (nClogn)0.5 using variant of decremental data structure by Even-Shiloach. Amortized cost per update is O(n2(nClogn)0.5) (details in the paper)

Approach:

2. Stitch together short paths from scratch to form long paths exploiting long paths decomposition <k <k <k <k <k <k <k

Rome Palmse Brno

Page 103: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

More details on stitching

1.  Build S deterministically, |S|=(Cnlogn)1/2 : O(n2) 2.  Compute APSP in S: O(|S|3) = O((Cnlogn)3/2) 3.  For each v in V, s in S, update distance by considering

mins’D(v,s’)+D(s’,s): O(n|S|2) = O(Cn2logn) 4.  For each u,v in V, update distance by considering

mins’D(u,s’)+D(s’,v): O(n2|S|) = O(n5/2(Clogn)1/2)

<k <k <k <k <k <k <k

Rome Palmse Brno

Perform the following tasks at each update: Always distances up to k=(Cnlogn)1/2 (IN e OUT trees)

O(1) query time O(n2.5 √C) space O(n2.5√C) update time ~ ~

Page 104: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

More details in

Long paths decomposition: [Ullman-Yannakakis’91] J.D. Ullman and M. Yannakakis. High-probability parallel transitive-closure algorithms. SIAM Journal on Computing, 20(1), February 1991

King’s algorithm: [King’99] Valerie KingFully Dynamic Algorithms for Maintaining All-Pairs Shortest Paths and Transitive Closure in Digraphs. FOCS 1999: 81-91

Page 105: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Main Ingredients

Long paths property

Decremental BFS

Path decompositions

Locally-defined path properties

Output bounded

Counting

Algebraic techniques

Page 106: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic shortest paths: roadmap

Shortest path trees

Long paths decomposition

Reduced costs

NSSSP Ramalingam-Reps ’96

Decremental BFS Even-Shiloach ’81

NAPSP King ’99

Locally-defined path properties

NAPSP/APSP Demetrescu-Italiano ’04

SSSP Frigioni et al ’98Demetrescu ’01

Page 107: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Heuristic to speed up Dijkstra (NAPSP)

y’

Dijkstra’s algorithm for NAPSP

Run Dijkstra from all vertices “in parallel”

Possibly insert (x,y’) into heap or decrease priority 3.

2. Scan only y’ for which (a,y’) shortest

(subpath opt.)

Can we do better?

Extract shortest pair (x,y) from heap:

x y

1.

a

Possibly insert (x,y’) into heap or decrease its priority 3.

y’ 2. Scan all neighbors y’ of y

Edge scanning bottleneck for dense graphs [Goldberg]

Extract shortest pair (x,y) from heap:

x y

1.

Page 108: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

x y πxy

Shortest path Shortest path Not a shortest path

Shortest path

x y πxy

A path is locally shortest if all of its proper subpaths are shortest paths

Locally Shortest Paths [Demetrescu-I., J.ACM04]

Page 109: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Locallyshortest paths

Locally shortest paths

Shortest paths

By optimal-substructure property of shortest paths:

Page 110: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

How much do we gain?

Running time on directed graphs with real non-negative edge weights

O(n2) space O( #LS-paths + n2 log n) time

Q.: How many locally shortest paths ?

Q.: How much can we gain in practice?

A.: #LS-paths ≤ mn. No gain in asymptopia…

Page 111: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

How many LSPs in a graph?

aaa

Locally shortest paths in random graphs (500 nodes)

0

5,000,000

10,000,000

15,000,000

20,000,000

25,000,000

0 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000

# edges

m*n#LS-pathsn*n

#LS-paths

m*n

n*n

Page 112: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Real-world Graphs?

Page 113: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Locally shortest paths in US road networks

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

DE NV NH ME AZ ID MT ND CT NM MA NJ LA CO MD NE MS IN AR KS KY MI IA AL MN MO CA NC

US states

average degree#LS-paths per pair

US road networks

Page 114: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Can we exploit this in practice?

aaa

Experiment for increasing number of edges (rnd, 500 nodes)

0

2

4

6

8

10

12

14

16

18

0 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000

Number of edges

DijkstraNew algorithm

Dijkstra'salgorithm

Algorithm basedon locally shortest paths

Page 115: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Theoretical analysis Bottlenecks, Heuristics

What we have seen so far:

Algorithm implementation

Deeper insights

More realistic models

Hints to refine analysis

Algorithm design

Experimental analysis

Page 116: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Bottlenecks, Heuristics

Return Trip to Theory:

Algorithm implementation

Theoretical analysis Deeper insights

More realistic models

Hints to refine analysis

Algorithm design

Experimental analysis

Page 117: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Back to Fully Dynamic APSP

Given a weighted directed graph G=(V,E,w),perform any intermixed sequence of the following operations:

return distance from x to y (or shortest path from x to y) Query(x,y):

update cost of edge (u,v) to w Update(u,v,w):

Page 118: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Recall Fully Dynamic APSP

•  Hard operations seem edge deletions (edge cost increases)

•  When edge (shortest path) deleted: need info about second shortest path? (3rd, 4th, …)

Shortest path Shortest path

x y πxy

•  Hey… what about locally shortest paths?

Candidate for being shortest path! Locally shortest path

Page 119: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Locally Shortest Paths for Dynamic APSP

Idea: Maintain all the locally shortest paths of the graph

How do locally shortest paths change in a dynamic graph?

Page 120: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Assumptions behind the analysis

Property 1 Locally shortest paths πxy are internally vertex-disjoint

This holds under the assumption that there is a unique shortest path between each pair of vertices in the graph

(Ties can be broken by adding a small perturbation to the weight of each edge)

x y

π1

π3

π2

Page 121: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Tie Breaking

Shortest paths are unique

Assumptions

In theory, tie breaking is not a problem

Practice

In practice, tie breaking can be subtle

Page 122: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Properties of locally shortest paths

Property 2 There can be at most n-1 LS paths connecting x,y

x y

This is a consequence of vertex-disjointess…

Page 123: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Appearing locally shortest paths

Fact 1 At most mn (n3) paths can start being locally shortest after an edge weight increase

x y

10

20

30

40

x y 100

10

20

30

40

100

Page 124: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Disappearing locally shortest paths

Fact 2 At most n2 paths can stop being locally shortest after an edge weight increase

π stops being locally shortest after increase of e

subpath of π (was shortest path) must contain e

shortest paths are unique: at most n2 contain e

Page 125: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Maintaining locally shortest paths

# Locally shortest paths appearing after increase: < n3

# Locally shortest paths disappearing after increase: < n2

The amortized number of changes in the set of locally shortest paths at each update in an increase-only sequence is O(n2)

Page 126: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

An increase-only update algorithm

This gives (almost) immediately:

O(n2 log n) amortized time per increase

O(mn) space

Page 127: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Maintaining locally shortest paths

x y

10

20

30

40

x y 100

10

20

30

40

What about fully dynamic sequences?

Page 128: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

x y

How to pay only once?

x y x y

This path remains the same while flipping between being LS and non-LS:

Would like to have update algorithm that pays only once for it

until it is further updated...

Page 129: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

x y

Looking at the substructure

x y

…but if we removed the same edge it would be a shortest path again!

It is not dead!

This path remains a shortest path after the insertion

This path is no longer a shortest path after the insertion…

Page 130: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Historical paths

x y

A path is historical if it was shortest at some time since it was last updated

historical path

Page 131: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Locally historical paths

Shortest path

Shortest path

x y

πxy Locally shortestpath

Historical path

Historical path

x y

πxy Locally historical

path

Page 132: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Key idea for partially dynamic

LSP SP

Page 133: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Key idea for fully dynamic

LHP

HP

LHP

SP HP

Page 134: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Putting things into perspective…

LHP

HP LSP SP

Page 135: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

The fully dynamic update algorithm

O(n2 log3 n) amortized time per update

Fully dynamic update algorithm very similar to partially dynamic, but maintains locally historical paths instead of locally shortest paths (+ performs some other operations)

O(mn log n) space

Idea: Maintain all the locally historical paths of the graph

Page 136: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

More details in

Locally shortest paths: [Demetrescu-Italiano’04] C. Demetrescu and G.F. Italiano A New Approach to Dynamic All Pairs Shortest Paths Journal of the Association for Computing Machinery (JACM), 51(6), pp. 968-992, November 2004

Dijkstra’s variant based on locally shortest paths:[Demetrescu-Italiano’06] Camil Demetrescu, Giuseppe F. Italiano: Experimental analysis of dynamic all pairs shortest path algorithms. ACM Transactions on Algorithms 2 (4): 578-601 (2006).

Page 137: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Further Improvements [Thorup, SWAT’04]

O(n2 (log n + log2 (m/n))) amortized time per update

O(mn) space

Using locally historical paths, Thorup has shown:

Page 138: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Bottlenecks, Heuristics

Another Return Trip to Theory:

Algorithm implementation

Theoretical analysis Deeper insights

More realistic models

Hints to refine analysis

Algorithm design

Experimental analysis

Page 139: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

How many LSPs in a graph?

aaa

Locally shortest paths in random graphs (500 nodes)

0

5,000,000

10,000,000

15,000,000

20,000,000

25,000,000

0 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000

# edges

m*n#LS-pathsn*n

#LS-paths

m*n

n*n

Page 140: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

LSP’s in Random Graphs

Peres, Sotnikov, Sudakov & Zwick [FOCS 10] Complete directed graph on n vertices with edge weights chosen independently and uniformly at random from [0;1]:

Number of locally shortest paths is O(n2), in expectation and with high probability.

This yields immediately that APSP can be computed in time O(n2), in expectation and with high probability.

Page 141: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Dynamic shortest paths: roadmap

Shortest path trees

Locally-defined path properties

Long paths decomposition

Reduced costs

NSSSP Ramalingam-Reps ’96

Decremental BFS Even-Shiloach ’81

NAPSP King ’99

NAPSP/APSP Demetrescu-Italiano ’04

SSSP Frigioni et al ’98Demetrescu ’01

Experimentalcomparison

Page 142: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

A comparative experimental analysis

Query Update Name Weight

Ramaling./Reps 96 (SIMPLE) D-RRL real O(mn + n2log n) O(1)

King 99 D-KIN [0,C] O(n2.5 (C log n)0.5) O(1)

Demetrescu/I. 04 D-LHP real O(n2) O(1) ~

Dijkstra 59 (FT 87) S-DIJ real O(mn + n2log n) O(1)

Demetrescu/I. 06 S-LSP real O(#LSP + n2log n) O(1)

(Dynamic) NAPSP algorithms under investigation

Page 143: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Experimental setup Test sets

Random (strongly connected)

US road maps (n = hundreds to thousands)

Pathological instances

Hardware (few years ago) Athlon 1.8 GHz - 256KB cache L2 - 512MB RAM

Pentium IV 2.2GHz - 512KB cache L2 - 2GB RAM

PowerPC G4 500MHz - 1MB cache L2 - 384MB RAM

IBM Power 4 - 32MB cache L3 - 64GB RAM

AS Internet subgraphs (thousands of nodes)

Random updates / pathological updates

Page 144: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Experimental setup

Operating systems Linux

Solaris

Windows 2000/XP

Mac OS X

Compilers & Analysis Tools gcc (GNU)

xlc (Intel compiler)

Microsoft Visual Studio

Metrowerks CodeWarrior

Valgrind (monitor memory usage)

Cachegrind (cache misses)

Page 145: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Implementation issues

For very sparse graphs, heap operations are crucial, so good data structures (buckets, smart queues, etc.) make a difference…

In our experiments, we were mainly interested in edge scans for different graph densities

Not the best possible implementations (some library overhead): we look for big (> 2x) relative performance ratios

A lot of tuning: we tried to find a good setup of relevant parameters for each implementation

Page 146: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Algorithm D-RRL [Demetr.’01] Directed graphs with real edge weights

O(1) query time O(n2) space O(mn+n2log n) update time

v

w T(v) T(s)

+

s

u +ε

Run Dijkstra variant only on nodes of the affected subtree (SIMPLE algorithm describedearlier)

Maintain n shortest path trees

Work on each tree after each update

Approach:

Page 147: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Algorithm D-KIN [King’99] Directed graphs with integer edge weights in [0,C]

O(1) query time O(n2.5 √C) space O(n2.5√C) update time ~ ~

1.  Maintain dynamically shortest paths up to length k=(nC)0.5 using variant of decremental data structure by Even-Shiloach

Approach:

2. Stitch together short paths from scratch to form long paths exploiting long paths decomposition

<k <k <k <k <k <k <k

Roma Lipari Napoli

Page 148: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Algorithm D-LHP [Dem.-Italiano’03]

O(1) time per query O(n2) time per update ~

Maintain locally historical paths (LHP): paths whose proper subpaths have been shortest paths…

Approach:

O(mn) space ~ Directed graphs with real edge weights

Locally historical paths

Locally shortest paths Shortest paths

Page 149: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Are LHPs useful in practice? (update time)

0

0,005

0,01

0,015

0,02

0,025

0 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000

Tim

e p

er u

pd

ate

(sec)

Number of edges

Experiment for increasing # of edges (rnd, 500 nodes)

D-RRL

D-LHP

D-RRL

D-LHP

Page 150: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

What about real graphs? (update time)

aaa

Experiments on US road networks

0

0.005

0.01

0.015

0.02

0.025

0.03

0.035

HI DE NV NH ME ID MT ND CT NM MA NJ LA CO MD NE MS IN AR KS KY MI IA AL MN MO CA NC

US states

D-RRLD-LHP

Page 151: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Zoom out to static (update time)

aaa

Experiments on US road networks

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

HI DE NV NH ME AZ ID MT ND CT NM MA NJ LA CO MD NE MS IN AR KS KY MI IA AL MN MO CA NC

US states

S-DIJD-RRLD-LHP

Page 152: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Big issue: the space wall

aaa

Experiments on US road networks

0

20

40

60

80

100

120

140

0 200 400 600 800 1000# nodes

Page 153: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

aaa

Experiments on bottleneck graphs (500 nodes, IBM Power4)

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

0 5000 10000 15000 20000 25000 30000 35000

# edges

D-RRL

S-DIJ

D-LHP

S-LSP

Worst-case instances

updates

Page 154: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Rel

ativ

e tim

e pe

rfor

man

ce D

-RLL

/D-L

HP

Number of edges (x 100)

D-LHP slower than D-RRL 1 2 3 4 5 6 7 8 9 10

D-LHP faster than D-RRL

Different HW platforms

0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4

IBM Power 4 Sun UltraSPARC IIi AMD Athlon

(32MB L3 cache) (256KB L2 cache) (2MB L2 cache)

OH NC

CA MO MN AL

IA MI KY

KS

AR IN

MS

NE MD CO LA NJ

MA CT NM

ND

MT

ID

AZ

ME NH

NV DE

IBM Power 4

Sun UltraSPARC IIi

AMD Athlon

Page 155: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Cache effects

Cache size

0.69 0.84

1.00 1.17

1.30 1.41

1.83

0.75 0.87 0.92

0.71

11.12

0.6 0.8

1.0 1.2 1.4 1.6 1.8 2.0

128KB 256KB 512KB 1MB 2MB 4MB 8MB 16MB 32MB

Simulated cache miss ratio D-RRL/D-LHP Performance ratio D-RRL/D-LHP on real architectures

UltraSPARC IIi Xeon

Athlon

1.59 Power 4

Colorado road network

Page 156: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

The big picture (update time) Experiment for increasing # of edges (rnd, 500 nodes, w=1..5)

0,001

0,01

0,1

1

10

100

0 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000Number of edges

Tim

e p

er

up

da

te (

sec)

S-DIJD-LHPD-KIND-RRLS-LSP

S-DIJ

D-KIN

S-LSP

D-RRL

D-LHP

Page 157: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

What did we learn for sparse graphs? Best that one could hope for (in practice):

Work only on the affected shortest paths Small data structure overhead

D-RRL (Dem.’01 implem. Ram-Reps approach):

Very simple Hard to beat! (but quite bad on

pathological instances) D-LHP (Dem-Ita’04): Can be as efficient as D-RLL (best with good memory hierarchy: cache, memory bandwidth)

D-KIN (King’99): Overhead in stitching and data structure operations

Page 158: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

What did we learn for dense graphs?

Locally shortest/historical paths can be very useful

Even on static algorithm S-LSP can beat S-DIJ by a factor of 10x in practice on dense graphs

Dynamic algorithm D-LHP is the fastest in practice on all the test sets and platforms we considered

Page 159: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Concluding remarks

#locally shortest paths ≈ #shortest paths in all the graphs we considered (real/synthetic)

Careful implementations might fully exploit this (by keeping data structure overhead

as small as possible)

Space wall! Time kills you slowly, but space can kill you right away…

With 5000 vertices, 80 bytes per vertex pair: quadratic space means 2GB

With current RAMs, that’s about it!

Page 160: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

More details in

Algorithm D-LHP: [Demetrescu-Italiano’04] C. Demetrescu and G.F. Italiano A New Approach to Dynamic All Pairs Shortest Paths Journal of the Association for Computing Machinery (JACM), 51(6), pp. 968-992, November 2004

Computational study of dynamic NAPSP algorithms:[Demetrescu-Italiano’06] C. Demetrescu, G. F. Italiano: Experimental analysis of dynamic all pairs shortest path algorithms. ACM Transactions on Algorithms 2 (4): 578-601 (2006).

Page 161: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Outline

Dynamic Graph Problems

Methodology & State of the Art

Algorithmic Techniques

Conclusions

Page 162: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

More Work to be done on Dynamic APSP

Space is a BIG issue in practice

More tradeoffs for dynamic shortest paths?

Roditty-Zwick, Algoritmica 2011 O(mn1/2) update, O(n3/4) query for unweighted ~

Worst-case bounds?

Thorup, STOC 05 O(n2.75) update ~

Page 163: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Some Open Problems…

Lower Bounds?

Page 164: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Some Open Problems…

Fully Dynamic Single-Source Shortest Path?

Nothing better than simple-minded approaches

Fully Dynamic Single-Source Single-Sink Shortest Path?

Nothing better than simple-minded approaches

In static case, those problems are easier than APSP…

Page 165: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Fully Dynamic SSSP (SSSS) not easier? Claim. If Fully Dynamic SSSS can be solved in time O(f(n)) per update and query, then also Fully Dynamic APSP can be solved in time O(f(n)) per update and query.

All-Pairs queryG(x,y) can be implemented in G’ as follows: updateG’ (s,x,0); updateG’ (y,t,0); queryG’ (s,t);

updateG’ (s,x, +∞); updateG’ (y,t, +∞)

G … …

s t

Edges from s to G and from G to t have cost +∞

G’

Page 166: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Some Open Problems…

Dynamic Maximum st-FlowDynamic algorithm only known for planar graphs O(n2/3 log8/3 n) time per operation I., Nussbaum, Sankowski & Wulf-Nilsen [STOC 2011] What about general graphs?

Dynamic Diameter Diameter():

what is the diameter of G? Do we really need APSP for this?

Page 167: Giuseppe F. Italiano - IoCcs.ioc.ee/ewscs/2012/italiano/dynamic1.pdf · Giuseppe F. Italiano! University of Rome ... Elementary operations take ... Algorithmics”. Cambridge University

Some Open Problems…

Dynamic Strongly Connected Components (directed graph G) SCC(x,y):

Are vertices x and y in same SCC of G? In static case strong connectivity easier than transitive closure….

Static Problem: Find Biconnectivity Components of Directed Graphs