Approximating Distances in Graphs Uri Zwick Tel Aviv

  • Slides: 59
Download presentation
Approximating Distances in Graphs Uri Zwick Tel Aviv University Otwarte wykłady dla doktorantów informatyki

Approximating Distances in Graphs Uri Zwick Tel Aviv University Otwarte wykłady dla doktorantów informatyki Instytut Informatyki Uniwersytetu Warszawskiego Kwietnia 27 -28, 2007

All-Pairs Shortest Paths APSP algorithm mn time n 2 space n by n distance

All-Pairs Shortest Paths APSP algorithm mn time n 2 space n by n distance matrix Input: A weighted undirected graph G=(V, E), where |E|=m and |V|=n. Output: An n n distance matrix.

Approximate Shortest Paths Let (u, v) be the distance from u to v. Multiplicative

Approximate Shortest Paths Let (u, v) be the distance from u to v. Multiplicative error Additive error An estimated distance ’(u, v) is of stretch t iff (u, v) ’(u, v) t · (u, v) An estimated distance ’(u, v) is of surplus t iff (u, v) ’(u, v) + t

Multiplicative and additive spanners Let G=(V, E) be a weighted undirected graph on n

Multiplicative and additive spanners Let G=(V, E) be a weighted undirected graph on n vertices. A subgraph G’=(V, E’) is a t-spanner of G iff for every u, v V we have G’(u, v) ≤ t G(u, v). Let G=(V, E) be a unweighted undirected graph on n vertices. A subgraph G’=(V, E’) is an additive t-spanner of G iff for every u, v V we have G’(u, v) ≤ G(u, v) + t.

Approximate Distance Oracles e P t. Pi. Sm chem mn. A 2 soprait nalg

Approximate Distance Oracles e P t. Pi. Sm chem mn. A 2 soprait nalg Weighted undirected graph mn n 1+1 1/k tim sp e ac e Stretch-Space tradeoff is u, v essentially optimal! /k n by n distance matrix Compact data structure O(1) query time δ’(u, v) stretch 2 k 1

1. All-pairs almost shortest paths (unweighted) a. An O(n 5/2)-time surplus-2 algorithm (ACIM’ 96)

1. All-pairs almost shortest paths (unweighted) a. An O(n 5/2)-time surplus-2 algorithm (ACIM’ 96) b. Additive 2 -spanners with O(n 3/2) edges. c. An O(n 3/2 m 1/2)-time surplus-2 algorithm (DHZ’ 96) 2. Multiplicative spanners (weighted graphs) d. (2 k 1)-spanners with n 1+1/k edges (ADDJS’ 93) e. Linear time construction (BS’ 03) 3. Approximate distance oracles (weighted graphs) f. Stretch=2 k 1 query time=O(1) space=O(kn 1+1/k) (TZ’ 01) 4. Spanners with sublinear distance errors (unweighted) g. Additive error O(d 1/(k 1)) with O(kn 1+1/k) edges (TZ’ 05)

All-Pairs Almost Shortest Paths unweighted, undirected graphs Surplus Time Authors 0 mn folklore 2

All-Pairs Almost Shortest Paths unweighted, undirected graphs Surplus Time Authors 0 mn folklore 2 n 5/2 Aingworth-Chekuri. Indyk-Motwani ’ 96 2 2 n 3/2 m 1/2 n 7/3 Dor-Halperin-Zwick ’ 96 2(k 1) n 2 (m/n)1/k n 2+1/(3 k 4) ” ” ”

O(n 5/2)-time surplus-2 algorithm unweighted, undirected graphs 1) Add each vertex v to A,

O(n 5/2)-time surplus-2 algorithm unweighted, undirected graphs 1) Add each vertex v to A, independently, with probability n 1/2. (Elements of A are “centers”. ) 2) From every center v A, find a tree of shortest paths from v and add its edges to E’. 3) For every non-center v A: a) If v has a neighbor u A, then add the single edge (u, v) to E’. b) Otherwise, add all the edges incident to v to E’. 4) Solve the APSP problem on the subgraph G’=(V, E’). O(n) O(m|A|) = O(n 5/2) O(m) O(n|E’|) = O(n 5/2)

Number of edges in E’ • The expected # of edges added to E’

Number of edges in E’ • The expected # of edges added to E’ in 2) is O(n 3/2). • The expected # of edges added to E’ in 3) is also O(n 3/2). Consider a vertex v of degree d If one of the neighbors of v is placed in A, then E’ will contain only one edge incident on v. v Hence, the expected number of edges incident to v added to E’ is at most d(1 n 1/2)d + 1 ≤ n 1/2 Exercise 0: Check it!

The surplus-2 algorithm Correctness – Case 1: No vertex on a shortest path from

The surplus-2 algorithm Correctness – Case 1: No vertex on a shortest path from u to v has a neighboring center. u v All the edges on the path are in E’. We find a shortest path from u to v.

The surplus-2 algorithm Correctness – Case 2: At least one vertex on a shortest

The surplus-2 algorithm Correctness – Case 2: At least one vertex on a shortest path from u to v has a neighboring center. (u, w)+1 u w’ w (w, v)+1 v We find a path from u to v of surplus at most 2

Additive 2 -spanners [ACIM’ 96] [DHZ’ 96] Every unweighted undirected graph G=(V, E) on

Additive 2 -spanners [ACIM’ 96] [DHZ’ 96] Every unweighted undirected graph G=(V, E) on n vertices has a subgraph G’=(V, E’) with O(n 3/2) edges such that for every u, v V we have G’(u, v) ≤ G(u, v) + 2. Additive 6 -spanners [BKMP ’ 04] Every unweighted undirected graph G=(V, E) on n vertices has a subgraph G’=(V, E’) with O(n 4/3) edges such that for every u, v V we have G’(u, v) ≤ G(u, v) + 6. Major open problem: Are there additive spanners with o(n 4/3) edges?

Exercise 1: Show that with high probability, all distances larger than 2 n 1/2

Exercise 1: Show that with high probability, all distances larger than 2 n 1/2 ln n are correctly computed by the O(n 5/2) time surplus 2 algorithm.

O(n 3/2 m 1/2)-time surplus-2 algorithm unweighted, undirected graphs 1) Add each vertex v

O(n 3/2 m 1/2)-time surplus-2 algorithm unweighted, undirected graphs 1) Add each vertex v to A, independently, with probability (n/m)1/2. (Elements of A are “centers”. ) 2) From every center v A, find distances to all other vertices in the graph. (Do not add edges to E’. ) 3) For every non-center v A: a) If v has a neighbor u A, then add the single edge (u, v) to E’. b) Otherwise, add all the edges incident to v to E’. 4) For every non-center vertex v A: a) Construct a set F(v)={ (v, w) | w A } of weighted edges. The weight of an edge (v, w) is (w, v). b) Find distances from v to all other vertices in the weighted graph G’(v)=(V, E’ F(v)).

O(n 3/2 m 1/2)-time surplus-2 algorithm Correctness – Case 2: At least one vertex

O(n 3/2 m 1/2)-time surplus-2 algorithm Correctness – Case 2: At least one vertex on a shortest path from u to v has a neighboring center. (u, w)+1 u w’ w v Consider the last vertex with a neighboring center. We find a path from u to v of surplus at most 2

All-Pairs Almost Shortest Paths weighted undirected graphs Stretch Time Reference 1 mn n 3/2

All-Pairs Almost Shortest Paths weighted undirected graphs Stretch Time Reference 1 mn n 3/2 m 1/2 n 7/3 n 2 Dijkstra ’ 59 2 7/3 3 Cohen-Zwick ’ 97 Some log factors ignores ” ”

Spanners Given an arbitrary dense graph, can we always find a relatively sparse subgraph

Spanners Given an arbitrary dense graph, can we always find a relatively sparse subgraph that approximates all distances fairly well?

Spanners [PU’ 89, PS’ 89] Let G=(V, E) be a weighted undirected graph. A

Spanners [PU’ 89, PS’ 89] Let G=(V, E) be a weighted undirected graph. A subgraph G’=(V, E’) of G is said to be a t-spanner of G iff δG’ (u, v) ≤ t δG (u, v) for every u, v V. Theorem: Every weighted undirected graph has a (2 k 1) -spanner of size O(n 1+1/k). [ADDJS’ 93] Furthermore, such spanners can be constructed deterministically in linear time. [BS’ 03] [RTZ’ 05] The size-stretch trade-off is optimal if there are graphs with (n 1+1/k) edges and girth 2 k+2, as conjectured by Erdös and others.

Exercise 2: Show that the following simple algorithm constructs, in O(m) time, a (2

Exercise 2: Show that the following simple algorithm constructs, in O(m) time, a (2 k 1)-spanner with at most n 1+1/k edges of any undirected unweighted graph. While the graph is not empty, choose a vertex v V. Let Ni(v) be the set of vertices of distance at most i from v. Let j be the smallest integer for which |Nj(v)| ≤ n 1/k |Nj 1(v)|. Add to the spanner a tree of shortest path from v to all vertices of Nj(v) and delete the vertices of Nj 1(v) and all the edges adjacent to them from the graph.

Exercise 3: The girth of a graph is the size of the shortest cycle

Exercise 3: The girth of a graph is the size of the shortest cycle in the graph. Use the construction of the previous exercise to show that the girth of any graph with at least n 1+1/k edges is at most 2 k. Girth Conjecture (Erdös and others): There are n-vertex graphs with Ω(n 1+1/k) edges that have girth > 2 k. Known for k=1, 2, 3, 5.

A simple spanner construction algorithm [Althöfer, Das, Dobkin, Joseph, Soares ’ 93] • Consider

A simple spanner construction algorithm [Althöfer, Das, Dobkin, Joseph, Soares ’ 93] • Consider the edges of the graph in non-decreasing order of weight. • Add each edge to the spanner if it does not close a cycle of size at most 2 k. • The resulting graph is a (2 k 1)-spanner. • The resulting graph has girth > 2 k. • Hence, number of edges in it is at most n 1+1/k.

If |cycle| 2 k, then red edge can be removed.

If |cycle| 2 k, then red edge can be removed.

Exercise 4: Let mg(n) be the maximum number of edges in an n-vertex graph

Exercise 4: Let mg(n) be the maximum number of edges in an n-vertex graph of girth g. Show that every n-vertex graph has a t-spanner with at most mt+2(n) edges and that this result is best possible.

Linear time spanner construction [Baswana-Sen ’ 03] • The algorithm is composed of k

Linear time spanner construction [Baswana-Sen ’ 03] • The algorithm is composed of k iterations. • At each iteration some edges are added to the spanner and some edges and vertices are removed from the graph. • At the end of the i-th iteration we have a collection of about n 1 i/k trees of depth at most i that contain all the surviving vertices of the graph.

Tree properties • The edges of the trees are spanner edges. • The weights

Tree properties • The edges of the trees are spanner edges. • The weights of the edges along every leaf-root path are non-increasing. • For every surviving edge (u, v) we have w(u, v) w(u, p(u)), where p(u) is the parent of u. w 3 i w 4 w 2 w 1 w 2 w 3 w 4 w 2

Notation Ai – roots of trees of the i-th iteration T(v) – the tree

Notation Ai – roots of trees of the i-th iteration T(v) – the tree rooted at v v T(v) u E(u, T(v)) – the edges connecting u and T(v). e(u, T(v)) – the lightest edge from E(u, T(v)). w(u, T(v)) – the weight of e(u, T(v)) (or ).

The i-th iteration Each vertex v Ai-1 is added to Ai with probability n

The i-th iteration Each vertex v Ai-1 is added to Ai with probability n 1/k. In the last iteration Ak . v 1 vr Ai v 2 u Let v 1, v 2, … be the vertices of Ai-1 such that w(u, T(v 1)) ≤ w(u, T(v 2)) ≤ … Let r=r(u) be the minimal index for which vr Ai. If there is no such index, let r(u)= |Ai 1|.

The i-th iteration (cont. ) v 1 vr Ai v 2 u For every

The i-th iteration (cont. ) v 1 vr Ai v 2 u For every vertex u that belongs to a tree whose root is in Ai-1 Ai: For every 1 ≤ j ≤ r : Add e(u, T(vi)) to the spanner. Remove E(u, T(vi)) from the graph Remove edges that connect vertices in the same tree. Remove vertices that have no remaining edges.

How many edges are added to the spanner? v 1 vr Ai v 2

How many edges are added to the spanner? v 1 vr Ai v 2 u E[r(u)] ≤ n 1/k Hence, the expected number of edges added to the spanner in each iteration is at most n 1+1/k.

What is the stretch? Let e be an edge deleted in the i-th iteration.

What is the stretch? Let e be an edge deleted in the i-th iteration. The spanner contains a path of at most 2(i 1)+1 edges between the endpoints of e. The edges of the path are not heavier than e Hence, stretch ≤ 2 k 1 i 1 e

Exercise 4: Complete the proof that the algorithm of Baswana-Sen algorithm produces a (2

Exercise 4: Complete the proof that the algorithm of Baswana-Sen algorithm produces a (2 k 1)-spanner with at most O(kn 1+1/k) edges. Show that it can be implemented to run in O(km) time. Note that a factor Exercise 5: of k is lost in the number of edges. Prove the correctness of the following variant of the Baswana-Sen algorithm: Perform only the first (k 1)/2 iterations of the original algorithm. (Assume that k is odd. ) For every pair of trees produced in the last iteration, find the lightest surviving edge that connects them and add it to the spanner.

Approximate Distance Oracles (TZ’ 01) e P t. Pi. Sm chem mn. A 2

Approximate Distance Oracles (TZ’ 01) e P t. Pi. Sm chem mn. A 2 soprait nalg Weighted undirected graph mn n 1+1 1/k tim sp e ac e Stretch-Space tradeoff is u, v essentially optimal! /k n by n distance matrix Compact data structure O(1) query time δ’(u, v) stretch 2 k 1

Approximate Distance Oracles [TZ’ 01] A hierarchy of centers A 0 V ; Ak

Approximate Distance Oracles [TZ’ 01] A hierarchy of centers A 0 V ; Ak Ai sample(Ai 1, n 1/k)

Bunches p 2(v) v p 1(v) A 0 = A 1 = A 2

Bunches p 2(v) v p 1(v) A 0 = A 1 = A 2 =

Lemma: E[|B(v)|] ≤ kn 1/k Proof: |B(v) Ai| is stochastically dominated by a geometric

Lemma: E[|B(v)|] ≤ kn 1/k Proof: |B(v) Ai| is stochastically dominated by a geometric random variable with parameter p=n 1/k.

The data structure Keep for every vertex v V: • The centers p 1(v),

The data structure Keep for every vertex v V: • The centers p 1(v), p 2(v), …, pk-1(v) • A hash table holding B(v) For every w V, we can check, in constant time, whether w B(v), and if so, what is (v, w).

Query answering algorithm Algorithm distk(u, v) w u , i 0 while w B(v)

Query answering algorithm Algorithm distk(u, v) w u , i 0 while w B(v) { i i+1 (u, v) (v, u) w pi(u) } return (u, w)+ (w, v)

Query answering algorithm w 3=p 3(v) A 3 w 2=p 2(u) A 2 w

Query answering algorithm w 3=p 3(v) A 3 w 2=p 2(u) A 2 w 1=p 1(v) A 1 w 0= u v

Analysis wi=pi(u) Ai Claim 1: wi 1=pi 1(v) Ai 1 δ(u, wi) + δ(wi,

Analysis wi=pi(u) Ai Claim 1: wi 1=pi 1(v) Ai 1 δ(u, wi) + δ(wi, v) ≤ (2 i+1)Δ ≤ (2 k 1)Δ i i 1) Claim 2: (i + δ(u, wi) ≤ iΔ , i even δ(v, wi) ≤ iΔ , i odd u (i 1) v

Exercise 6: What is the stretch of a query answering algorithm that does not

Exercise 6: What is the stretch of a query answering algorithm that does not swap u and v in each iteration, i. e. , finds the smallest i for which w=pi(u) B(v) and returns (u, w)+ (w, v) ?

Where are the spanners? Define clusters, the “duals” of bunches. For every u V,

Where are the spanners? Define clusters, the “duals” of bunches. For every u V, put in the spanner a tree of shortest paths from u to all the vertices in the cluster of u.

Bunches and Clusters

Bunches and Clusters

Clusters w A 0 = A 1 = A 2 =

Clusters w A 0 = A 1 = A 2 =

Computing Clusters Lemma: If v C(w) and u lies on a shortest path from

Computing Clusters Lemma: If v C(w) and u lies on a shortest path from w to v, then u C(w). Using this fact, each cluster can be computed by a modified version of Dijkstra’s algorithm that only examines edges that touch vertices of the cluster.

Exercise 7: Show that the subgraph composed of the shortest path trees of the

Exercise 7: Show that the subgraph composed of the shortest path trees of the clusters is a (2 k 1)-spanner with an expected number of O(kn 1+1/k) edges.

Approximate distance oracles - summary Preproceesing time = O(kmn 1+1/k) Space = O(n 1+1/k)

Approximate distance oracles - summary Preproceesing time = O(kmn 1+1/k) Space = O(n 1+1/k) Query time = O(k) Stretch ≤ 2 k 1 The space/stretch tradeoff is essentially optimal (modulo the girth conjecture) Can the query time be reduced to O(1)? Manor and Naor (2006) recently gave a solution with space = O(n 1+1/k) , stretch = O(k) , query time = O(1)

Exercise 8: Show that the subgraph composed of the shortest path trees of the

Exercise 8: Show that the subgraph composed of the shortest path trees of the clusters is a (2 k 1)-spanner with an expected number of O(kn 1+1/k) edges.

Additive Spanners Let G=(V, E) be a unweighted undirected graph. A subgraph G’=(V, E’)

Additive Spanners Let G=(V, E) be a unweighted undirected graph. A subgraph G’=(V, E’) of G is said to be an additive t-spanner of G iff δG’ (u, v) ≤ δG (u, v) +t for every u, v V. Theorem: Every unweighted undirected graph has an additive 2 -spanner of size O(n 3/2). [ACIM ’ 96] [DHZ ’ 96] Theorem: Every unweighted undirected graph has an additive 6 -spanner of size O(n 4/3). [BKMP ’ 04] Major open problem Do all graphs have additive spanners with only O(n 1+ε) edges, for every ε>0 ?

Spanners with sublinear surplus Theorem: For every k > 1, every undirected graph G=(V,

Spanners with sublinear surplus Theorem: For every k > 1, every undirected graph G=(V, E) on n vertices has a subgraph G’=(V, E’) with O(n 1+1/k) edges such that for every u, v V, if δG(u, v)=d, then δG’(u, v)=d+O(d 1 1/(k 1)). d d + O(d 1 1/(k 1)) Extends and simplifies a result of Elkin and Peleg (2001) Improved recently by Pettie (2007)

The construction of the approximate distance oracles, when applied to unweighted graphs, produces spanners

The construction of the approximate distance oracles, when applied to unweighted graphs, produces spanners with sublinear surplus! We present a slightly modified construction with a slightly simpler analysis.

Balls p 2(u) u p 1(u) A 0 = A 1 = A 2

Balls p 2(u) u p 1(u) A 0 = A 1 = A 2 =

Spanners with sublinear surplus Select a hierarchy of centers A 0 A 1 …

Spanners with sublinear surplus Select a hierarchy of centers A 0 A 1 … Ak 1. For every u V, add to the spanner a shortest paths tree of Ball[u].

The path-finding strategy Suppose we are at u Ai and want to go to

The path-finding strategy Suppose we are at u Ai and want to go to v. Let Δ be an integer parameter. If the first xi = Δi Δi 1 edges of a shortest path from u to v are in the spanner, then use them. Otherwise, head for the (i+1)-center ui+1 nearest to u. ► The distance to ui+1 is at most xi. (As u’ Ball(u). ) ui+1 Ai+1 xi u Ai u’ xi v

The path-finding strategy We either reach v, or at least make xi = Δi

The path-finding strategy We either reach v, or at least make xi = Δi Δi 1 steps in the right direction. Or, make at most xi = Δi Δi 1 steps, possibly in a wrong direction, but reach a center of level i+1. If i=k 1, we will be able to reach v. ui+1 Ai+1 xi u Ai u’ xi v

The path-finding strategy After at most Δi steps: ui we reach v or distance

The path-finding strategy After at most Δi steps: ui we reach v or distance to v decreased by Δi 2Δi 1 xi = Δ i 1 x i 2 Δi 1 u’ x 1 x 0 u 0 v

The path-finding strategy After at most Δi steps: we reach v distance to v

The path-finding strategy After at most Δi steps: we reach v distance to v decreased by Δi 2Δi 1 Surplus 2Δi 1 Stretch The surplus is incurred only once!

Sublinear surplus This holds for any Δ ! Δ is part of the analysis,

Sublinear surplus This holds for any Δ ! Δ is part of the analysis, not the construction.

Improved spanners with additive error Pettie (2007) has recently obtained improved spanners with additive

Improved spanners with additive error Pettie (2007) has recently obtained improved spanners with additive errors.

Main open problems • Additive spanners? • Approximate distance oracles with additive errors?

Main open problems • Additive spanners? • Approximate distance oracles with additive errors?