1 sadna in algorithms haim kaplan and svetlana olonetsky tel aviv university, fall 07/08
Post on 19-Dec-2015
215 views
TRANSCRIPT
1
Sadna in AlgorithmsSadna in Algorithms
Haim Kaplan and Haim Kaplan and
Svetlana OlonetskySvetlana Olonetsky
Tel Aviv University, fall 07/08Tel Aviv University, fall 07/08
3
What do you have to do:
• Choose algorithms to implement
• Understand them well
• Choose the graphs you’d run on
• The structure/language of your program
What is the purpose ? Why do you do it ?
There should be a goal, something that you do not know in advance, interesting graph classes
4
Inspiration
There has been a lot of work recently on so called “algorithm engineering”:
Three yearly conferences:
1) WAE
2) ALENEX
3) ESA (track B)
7
There are many There are many variationsvariations
graph is undirected/directed
weights: negative/nonnegative real/integer
given pair(s)/single source/all pairs
one shot/build a data structure or spaner
exact/approximate
randomized/deterministic
8
Dijkstra’s shortest path algorithm
Let G = (V,E) be a weighted (weights are non-negative) undirected/directed graph, let s V. Want to find the distance (length of the shortest path), d(s,v) from s to every other vertex.
s
3
3 2
3
2
1
9
Dijkstra: Maintain an upper bound d(v) on d(s,v).
Every vertex is either scanned, labeled, or unlabeled.
Initially: d(s) = 0 and d(v) = for every v s.s is labeled and all others are unlabeled.
• Pick a labeled vertex with d(v) minimum. Make v scanned.
For every edge (v,w) if d(v) + w(v,w) < d(w) then
1) d(w) := d(v) + w(v,w)
2) label w if it is not labeled already
10
Dijkstra’s shortest path algorithm (implementation)
Maintain the labeled vertices in a heap, using d(v) as the key of v.
We perform n delete-min operations and n insert operations on the heap. O(n log(n))
For each edge we may perform a decrease-key.
With regular heaps O(m log (n)).
But if you can do decrease-key in O(1) time then you can implement Dijkstra’s algorithm to run in O(n log(n) + m) time !
11
Dial’s implementation
• Assume that weights are small integers
• Maintain vertices in an array according to their distance label
16
Analysis
• Let C-1 be the maximum length of an arc
• What should be the length of the array ?
• What is the running time ?
• How can you do better ?
21
Goldberg et al
• Has done extensive experimental work on Dijkstra’s algorithm
• It may be interesting to repeat some of them ? Run on different graph classes, check new ideas, etc
34
• Define potential function π(v) and modify lengths:– ℓ(v,w) = c(v,w) − π(v) + π(w)– ℓ(v,w): reduced cost of arc (v,w).
• All s-t paths change by same amount: π(t) − π(s).
• A* search: – Equivalent to Dijkstra on the modified graph: correct if ℓ(v,w) ≥ 0 (π is feasible). • Take π(v) to be lower bounds on dist(v, t)
A* search
36
Where do we get lower bounds ?
• Use landmarks
dist(v,w) ≥ dist(A,w) − dist(A,v)
dist(v,w) ≥ dist(v,A) − dist(w,A)
A
v w
A
v w
38
Landmark selection
• There has been research on it:– selection at preprocessing – selection for the query
39
Reach
• Reach of v with respect to P:reach(v, P) = min{ dist(s, v) , dist(v, t) }
• Reach of v with respect to the whole graph: reach(v) = maxP {reach(v, P)}, over all shortest paths P that contain v [Gutman’04].
• Intuition:– vertices on highways have high reach;– vertices on local roads have low reach.
v ts
40
How do you use reaches
• While scanning an edge (v,w):– If reach(w) < min{d(s, v) + ℓ(v,w), LB(w, t)}, then w can be pruned.
ts
w
• The lower bound is natural if the search is bidirectional
v
42
Shortcuts• Consider a sequence of vertices of degree two on the path below:
– they all have high reach;
ss t
1000 1000
1000 1010 1020 1030 1040 1030 1020 1010 1000
10 1010 10 1010 10 10
43
Shortcuts
ss t
1000 1000
1000 1010 1020 1030 1040 1030 1020 1010 1000
10 1010 10 1010 10 10
80
Add a shortcut:– single edge bypassing a path (with same length).– assume ties are broken by taking path with fewer nodes.
44
Shortcuts
ss t
1000 1000
1000 60 50 40 30 40 50 60 1000
10 1010 10 1010 10 10
80
Decrease reaches
45
Shortcuts
ss t
1000 1000
1000 60 50 40 30 40 50 60 1000
10 1010 10 1010 10 10
80
Can add more nested shortcuts
4040
46
Shortcuts
ss t
1000 1000
1000 20 10 20 30 20 10 20 1000
10 1010 10 1010 10 10
80
Can add more nested shortcuts
4040
49
Spanners
Let G be a weighted undirected graph.
A subgraph H of G is a t-spanner of G
iff u,vG,
H(u,v) t G(u,v) .
Awerbuch ’85Peleg-Schäffer ‘89
51
t-spanner
• Computing a t-spanner of smallest possible size is NP-complete.
• For a graph on n vertices, how large can a t-spanner be ?
u v 2-spanner may require Ω(n2) edges
52
Theorem
For every k>1, every weighted
undirected graph on n vertices has
a (2k-1)-spanner with at most
n1+1/k edges.
Tight for k=1,2,3,5. Conjectured to be tight for
any k equivalent to a girth conjecture of
Erdös.
53
Proof/Algorithm: Consider the edges in non-decreasing
order of weight.
If an edge closes a cycle of length ≤ 2k
discard it, otherwise add it.
The resulting graph is a (2k-1)-spanner
and it does not contain a cycle of length
≤ 2k.
Such graph has at most n1+1/k edges.[Althöfer, Das, Dobkin, Joseph, Soares ‘93]
69
Correctness
• Why is this a 3-spanner ?
• Show:
Where the weight of the red edges is smaller than the weight of the green one
74
(a,b)-Spanners
Let G be an unweighted undirected graph.
A subgraph H of G is an (a,b)-spanner of G
iff u,vG,
H(u,v) a G(u,v) + b .
(Dor-Halperin-Zwick ’96, a=1)
Peleg-Elkin ’01Baswana, Kavitha, Mehlhorn, Pettie ‘05Thurup Zwick ‘06