Undirected Single-Source Shortest Paths with Positive - E

Undirected Single-Source
Shortest Paths with Positive
Integer Weights in Linear Time
MIKKEL THORUP
1999 Journal of the ACM
Presenters



資訊四 巨彥霖
資訊四 羅婉嫣
資訊四 許恒瑞
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
Introduction(1)

Mikkel Thorup

http://www.diku.dk/~mthorup/
Introduction(2)
S ingle Source S hortest Path
Shortest path
problem
Shortest path
S
Shortest path
Given a positively weighted graph G with a source vertex s,
find the shortest path from s to all other vertices in the graph
Introduction(3)
History

Since 1959, all developments in SSSP have
been based on Dijkstra’s algorithm (1959)
Dijkstra’s algorithm(1)
D(v)

Notation:
a G
set=S(V, E)
V
 |v |= n,| E|= m
 v  S : D(v) = d(v)
 weighted function l : edge  positive integer



 v S
If (v, w)
w) = ∞
 E , define l(v,v can
go to S
∞
80
: D(v) = min u S { d(u) + l(u, v) }
d(v) : distance from s to v
D(v) : super distance
v can go to S
 D(v) ≧ d(v)
53
D(v) : super distance
d(v)
10
20
13
Dijkstra’s algorithm(2)
v6 v7 v8
v8
v4 v5
v5 v6
V = { v1}v2 v3 v4
v1
min
v2
v3
0
4
∞
7
6
∞
S={ }
v5
v4
visit
Initially
v3
v5
7
∞
∞
7
v8
v6
v4
min
v2
v1
v7
5
∞
6
v8
v7
v6
Introduction(3)
History
Thorup’sfusion
priority
queue
:
Raman
:
Fredman
&
Willard’s
trees
:
Fredman &Fredman
Tarjan Fibonacci
heaps
: heaps
1
&
Willard’s
atmoic
:
Applying William’s heap
:
Olog
(m

n
log
nlog log
) n)
O
(
m

n
log
n
O
(
m
n
)
Simple : O(m On(m
log log n)
O(m log n) log nn)log n /(1996)
(1996)
(1987) (1993)
O(n 2  m) (1964)
O(m)
(1994)
our target
!!
Dijkstra’s
algorithm
(1959)
Introduction(4)
In fact, Dijkstra’s algorithm can be
implemented in linear time  linear time sorting
( [Fredman & Tarjan 1987] , [Thorup 1996] )
Since we do not know how to sort in linear time,
this implies that we are deviating from
Dijkstra’s algorithm in that we do not visit the
vertices in order of increasing distance from s.
Our algorithm is based on a hierarchical
bucketing structure.
 may visit the vertices in any order
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
Preliminary(1)


Lemma 1
 If v S\V minimize D(v) , D(v) = d(v)
Lemma 2

minD(V\S) = mind(V\s) is non-decreasing
Preliminary(2)

Notation:

x >> i



i
is [ x / 2 ]
If x ≦ y => x >> i ≦ y >> i
If W  V , minD(W) >> i

is (min{ D(w) | w W }) >> i
Preliminary(3)

Bucket

which elements can be inserted and deleted,and
from which we can pick out an unspecified
element.

each operation should be supported in constant
time.
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
Avoiding the Sorting Bottleneck(1)

Dijkstra’s algorithm


visit the vertices in order of increasing D(v)
New approach


visit the vertices where D(v) = d(v)
D(v) ≧ min D(V\S)
Avoiding the Sorting Bottleneck(2)

0
∞
4
∞
∞
5
V1

∞
δ
V2
∞
V3
For some i, v Vi\S,
D(v) = min D(Vi\S)
≦ min D(V\S) + δ
d(v) = D(v)
Avoiding the Sorting Bottleneck(3)

Criteria on D(v) = d(v)




D(v) = min D(Vi\S) ≦ min D(V\S) + δ
<= min D(Vi\S) ≦ min D(V\S) + 2α
<= min D(Vi\S) >> α ≦ min D(V\S) >> α
Bucketing structure
0
j
i
1
2
…
3
4
D(v) ≦ Σe l(e)
ix min D(Vi\S)
Δ+>>
2α
Δ = Σe l(e) >> α
…
content
∞
index
Avoiding the Sorting Bottleneck(4)

SSSP algorithm A
δ = 20 , α = 0
7
∞
4
∞
0
min D(V\S)
= min
d(V\S)
B(min
D(Vi\S)
>> α)
= i is
nondecreasing
6
∞
ix
∞
5
∞
V1
∞
δ
V2
∞
V3
0
1
2
3
2
4
1
5
…
2 3
…
6 ∞7
Avoiding the Sorting Bottleneck(5)

SSSP algorithm A
Δ = Σe l(e) >> α
δ = 2α
O(m + Δ) + cost of maintaining min D(Vi\S) for each i
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
The Component Hierarchy(1)

Definition



Gi:the subgraph of
G with l(e) < 2i
[v]i:the connected
component on level i
containing v
children of [v]i:[w]i-1,
w  [v]i
v
[w]11
[v]
vw
G123o = G
G
G
[v]2
The Component Hierarchy(2)

Definition


[v]i is a min-child of [v]i+1
if min D([v]i-) >> i = min D([v]i+1-) >> i
[v]i is minimal if [v]j is a min-child of [v]j+1 for j =
i, …, b-1
[v]2
[v]1
v
The Component Hierarchy(3)
Dijkstra’s algorithm
visit v, if v V\S minimizes D(v)
 i, min D([v]i-) >> i = D([v]i+1-) >> i = D(v) >> i => [v]0 minimal
minimal D(v) = d(v)
[v]0 minimal
D(v) = d(v)
[v]0 minimal
The Component Hierarchy(4)
lemma 8
If v S and [v]i is minimal, min D([v]i-) = min d([v]i-).
In particular, D(v) = d(v) if [v]0 = {v} is minimal.
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
Visiting Minimal Vertices(1)

Definition



Lemma 10


visiting a vertex requires that [v]0 = {v} is minimal
when v is visited, v is moved to S and relax
For all [v]i,
max d([v]i\[v]i-) >> i-1 ≦ min d([v]i-) >> i-1
Lemma 11

min D([v]i-) >> i = min d([v]i-) >> i, visiting w
changes min D([v]i-) >> i, and the change in min
D([v]i-) >> i is increased by one
Visiting Minimal Vertices(2)

Lemma 12, 13

If [v]i has once been minimal, in all future,
min D([v]i-) >> i = min d([v]i-) >> i
Visiting Minimal Vertices(3)

SSSP algorithm B,C
Visit([s]i)
s
0
∞
4
5
d(w) >> i = min D([s]i-) >> i
min D([w]i-1-) >> i - 1
= min D([s]i-) >> i - 1
∞
∞
[w]i minimal
Visit([w]i-1)
∞
∞
[s]3120,=i G,
=1
0i = 3
2
Visiting Minimal Vertices(4)
Towards Linear Time !!
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
Towards Linear Time(1)

Component tree
Number of nodes
 2n 1
(e)  22
1
a
3
1
b
2
3
1
d
(e)  2
3
2
f
a
b
e
2
1
1
c
d
e
f
c
Towards Linear Time(2)

Linear size bucket structure
for all children wh of vi
ix ([v]i )  min D([v]i )  i  1
bucket wh in B(vi , min D(w )  i  1)

h
ix0 ([v]i )  min d ([v]i )  i  1
ix ([v]i )  max d ([v]i )  i  1
0
j
i
1
2
…
3
4
… …
…
ix0
ix
Δ+ 2
content
index
∞ content
ix∞
Δ = Σe l(e) >> α
index
Towards Linear Time(3)

Lemma 18. The total number of relevant buckets is
< 4m + 4n
Diameter of [v]I is bounded by

=> max d ([v]i )  min d ([v]i ) 
Define
([v]i ) 

e[ v ]i
e[ v ]i

e[ v ]i
(e) / 2i 1
=> ix ([v]i )  ix0 ([v]i )  ([v]i )
 ( e)

(e)
Towards Linear Time(4)

Lemma 18. The total number of relevant buckets is
< 4m + 4n
([v]i )  e[ v ] (e) / 2i 1


i 1

1  ([v]i )    2   (e) / 2 

[ v ]i 
[ v ]i  
e[ v ]i


i
# node in  is  2n 1
i 1

(
e
)
/
2

 4n 
[ v ]i  ,e[ v ]i
 4n  
i 1

(
e
)
/
2

 4n  
j
i 1
2
/
2

eE [ v ]i e
2
i j
j
/2
i 1
eE [ v ]i e
j
2 j  42nj  2 4  4n  4m
 j 1  j  j 1    4
2
2 e2E

j  log 2 (e)  1
Towards Linear Time(5)
Towards Linear Time(6)
O(m)
Towards Linear Time(7)
Towards Linear Time(8)
O(m)
0
0
ix0
min D([v]i )  i  1
0
0
0
…
0
content
…
ix∞
index
ix0 ([v]i )  ([v]i )
Towards Linear Time(9)
Total: O(m)
Total: O(m)
Total: O(n)
Total: O(m)
Towards Linear Time(10)


Assume that the component tree  has been
computed in linear time. Then no more than O(m)
time and space is needed to solve the SSSP
problem
How to construct the component tree

?
Outline







Introduction
Preliminary
Avoiding the Sorting Bottleneck
The Component Hierarchy
Visiting Minimal Vertices
Towards Linear Time
The Component Tree
The Component Tree(1)
all edges of weight  2i on level i
msb( x)  log 2 x
construct a minimum spanning tree M in linear tim e
[v] i  Gi
[v]iM  (V ,{e  M | (e)  2i })
 (e) 
e[ v ]i
M

(
e
)

diameter
([
v
]

i )  diameter ([v]i )
e[ v ]iM
The Component Tree(2)

Use union-find operation

Let e1, …, en-1 be the edges of M sorted
according to msb((ei ))

msb((ei ))  msb((ei 1 ))
X

X(

{)find (v),s(find
(u0)}
v
)

union
v
,
u
c
(
v
)
0
msb
(

(
e
))

msb
(

(
e
))
?
Yes!
!
msb
(

(
e
))

msb
(

(
e
))
?
No!
i
i

1
number

1
i of nodes 
i 12n
The
Component
Tree(3)
ss (
v)) s s(cfind
 (v, u )
 0(,uX))
find
(sv() find

(v))0(
v1
v2
4
XXX{{{vvv444,,,vv555,},vv66,},
v7
,sv18}2X '  {v4 , v7 }
s
v3 v1,v2,v3,v4,v5,v6,v7,v8
3
2
v2,v3,v4,v5,v6,v7,v8
v4
5
1
v5
2
4
1
v6
1
v7,v8
2
1
v7
v4,v5 ,v6
v1
v8
v2
v3
v4
v5
v6
v7
v8