Document 11045784

advertisement
\
HD28
.M4.14
ALFRED
P.
WORKING PAPER
SLOAN SCHOOL OF MANAGEMENT
FASTER ALGORTTHlvlS FOR THE
SHORTEST PATH PROBLEM
Ravindra K. Ahuja
Kurt Mehlhorn
James B. Orlin
Robert E. Tarjan
Sloan W.P. No. 2043-88
April 1988
MASSACHUSETTS
INSTITUTE OF TECHNOLOGY
50 MEMORIAL DRIVE
CAMBRIDGE, MASSACHUSETTS 02139
FASTER ALGORITHMS FOR THE
SHORTEST PATH PROBLEM
Ravindra K. Ahuja
Kurt Mehlhorn
James B. Orlin
Robert
Sloan W.P. No. 2043-88
E.
Tarjan
April 1988
Problem
Faster Algorithms for the Shortest Path
Ravindra K. Ahuja*
Sloan School of Management
M.I.T., Cambridge, MA. 02139
,
USA
Kurt Mehlhorn
FB
10, Universitat
des Saarlandes
66 Saarbriicken,
FEDERAL REPUBLIC OF GERMANY
James
B. Orlin
Sloan School of Management
M.LT., Cambridge, MA. 02139,
Robert
E.
USA
Tarjan
Department of Computer Science
Princeton University,
Princeton,
NJ 08544, USA
and
A.T.
&
T. Bell Laboratories
Murray HUl, N] 07974
On
leave from Indian Institute of Technology,
Kanpui
,
USA
-
208 016
,
INDIA
M.I.T.
Ai'G
LIBRARIES
1
1988
RECEiVEO
Faster Algorithms for the Shortest Path
Problem
Abstract
In this paper,
we
present the fastest
known
algorithms for the shortest path
We
consider networks with n nodes
problem with nonnegative integer arc lengths.
and
m
and
arcs
in
which C represents the
new
algorithms are obtained by implementing Dijkstra's algorithm using a
we
structure which
consists of
OGog
call a redistributive
Our
largest arc length in the network.
The one-level
heap.
data
redistributive heap
C) buckets, each with an associated range of integer numbers. Each
bucket stores nodes whose temporary distance labels
lie in its
range.
Further, the
ranges are dynamically changed during the execution, which leads to a redistribution
The resulting algorithm runs
of nodes to buckets.
two-level redistributive heap,
0(m +
n log C/ log log nC).
we improve
Finally,
we
reduce the complexity of our algorithm
in
0(m
pol)Tiomial
-i-
nVlog n
bound
our algorithms
of
to
model
0(m
+ n log C)
time. Using a
the complexity of this algorithm to
0(m
is
-i-
n VlogC
bounded by
)
.
This algorithm, under
a polynomial function of n,
time, which improves over the best previous strongly
+ n log n) due to
the semi-logarithmic
in
takes Flog x/log nl
that in this
)
0(m
use a modified version of Fibonacci heaps to
the assumption that the largest arc length
runs
in
Fredman and
Tarjan.
model of computation.
We
In this
time to perform arithmetic on integers of value
of computation,
sufficiently large values of C.
some
also analyse
x.
model,
It is
it
shown
of our algorithms run in linear time for
The
problem
shortest path
one of the most well-studied combinatorial
is
Algorithmic developments concerning this problem have
optimization problems.
proceeded along two directions:
development of algorithms that are superior
(i)
from worst-case complexity point of view
Kaas and
1982], Boas,
and
(ii)
Gilsinn and Witzgall [1973], Dial
Glover
et. al
Fredman and Tarjan
Zijistra [1977],
development of algorithms
Dijkstra [1959], Johnson [1977a, 1977b,
(e.g.,
[1984]
and Gabow
,
[1985]);
that are very efficient in practice (e.g.. Dial [1969],
el. al
[1979]
,
Denardo and Fox
Pape
[1979],
and
[1980],
[1985]).
two directions have not been very complementary.
Surprisingly, these
The
algorithms that achieve the best worst-case complexity have generally not been
attractive empirically
,
and the algorithms
have performed well
that
in practice
have
we
new
generally faUed to have an attractive worst-case bound. In this paper,
implementations of Dijkstra's algorithm intended
assumption
bounded by
that arc lengths are
a
to
bridge this gap.
Let
Cjj
G
= (N, A)
node
,
m= A
I
I
€
(i, j)
A
and C = max
network called the
of the
be
assume
We
otherwise.
Let A(i) =
.
(Cjj
:
source.
(i, j)
that all
€ A)
((i, j)
.
e A:
Further,
j
s
to
and
is
5,
and scans
nodes.
arcs in A(i)
i
is to
identify
that all arithmetic operations
0(1) time.
In
is
all
a
the divisions
power
of
method
At each
iteration, the
label,
makes
to revise the distance labels of adjacent
all
2.
to solve
d(j)
for
nodes into two subsets: permanently labeled
with smallest distance
The method stops when
a
unless stated
Dijkstra's algorithm maintains a distance label
nodes and temporarily labeled nodes.
temporarily labeled node
2,
possibly the most well-known
a partition of the set of
e N.
be a distinguished
s
logarithms in this paper are base
Dijkstra's algorithm [1959]
i
every other node in the network.
further assume, except in Section
the shortest path problem.
e N), for each
let
(multiplications) in the paper, however, the divisor (multiplier)
j
but very sparse
all
The shortest path problem
(including multiplication and division) take
each node
these
,
efficient in practice.
path of the shortest length from the source
We
n
the
be a directed network with a nonnegative integer arc length
associated with each arc
Let n = INI
to
Under
polynomial function of
algorithms achieve the best possible worst<ase complexity for
graphs and yet are simple enough
present
algorithm selects a
its
label permanent,
temporarily labeled
nodes are permanently labeled.
implementation of the algorithm runs
Dijkstra's original
bound
queue data structures
priority
number
the
if
following table indicates such improvements
of arcs
much
is
Tliis
improved using clever
the best possible for fully dense networks, but can be
is
0(n'') time.
in
than
less
max
In the table, d =
(2,
n'^.
The
Fm/nl) and
represents the average degree of a node.
Due
#
Running Time
to
1.
WUliams
2.
Johnson [1977a]
0(m
0(m
3.
Johnson [1977b]
0(m log
4.
Boas, Kaas, and Zijlstra [1977]
0(C +
5.
Johnson [1982]
6.
Fredman and Tarjan
7.
Gabow[1985]
0(m log log C)
0(m + n log n)
0(m log^j C)
Table
(1964]
[1984]
Running times
1.
log
log^
assumption
is
C
is
bounded by
known
n),
log
C
+ n log
C
log log C)
m log log C)
of polynomial shortest path problems.
For the sake of comparing the above algorithms,
assumption that
n)
we make
a p>olynomial function in n,
as the similarity
(i,e.,
C
the reasonable
= 0(n^^^'). This
assumption (Gabow [1985]).
Under
this
assumption, Fredman and Tarjan's implementation using Fibonacci heaps runs
faster than others for all classes of
method
Johnson [1982] appears more
of
In this paper,
heap,
graphs except very sparse ones, for which the
and we use
it
we
to
implement
and two-level versions
consists of
Odog
describe a
attractive.
new
data structure that
Chjkstra's algorithm.
of this data structure.
A
We
we
call the redistributive
consider both
one-level
one-level redistributive heap
C) buckets, each with an associated range of integer numbers. Each
bucket stores nodes whose temporary distance labels
lie in its
range.
The ranges
buckets are changed dynamically, which leads to redistribution of nodes
buckets.
The
resulting algorithm runs in
two-echelon) bucket system,
0(m
+ n log
structure
0(m
0(m
C/
further
+ nVlog
+ n
log log nC)
C
Vlog n
).
)
.
we improve
The use
reduces
Under
0(m
among
+ n log C) time Using a two-level
(or
the complexity of our algorithm to
of a modified version of the Fibonacci
the
of
complexity
of
our
heap data
algorithm
to
the similarity assumption, this algorithm runs in
time and improves the running time of Fredman and Tarjan's
shortest path algorithm.
data structures which
Our
Further, the
make them
proposed by Johnson [1977b],
buckets,
we
two of our algorithms use very simple
from an implementation viewpoint.
attractive
method uses
one-level bucket
simpler and more
first
same data
essentially the
except that our search technique
Whereas Johnson uses binary search
efficient.
use sequential search. Consequently, his algorithm
Our
slower than our algorithm.
is
two-level bucket approach
is
structure as
simultaneously
nodes into
to insert
OGog
log C) times
may be viewed
as a
hybrid between Johnson's 11982] and Denardo and Fox's [1979] algorithm.
Our algorithms
are computationally attractive even
arguably inappropriate.
computation
in
is
It
more
We
arithmetic operations take time 0(1),
is
In this case, the uniform
realistic to
cost 0(1).
adopt the semi-logarithmic model
of
to the length of
We
also
assume
that
C
= o(2"°^^0;
0(n°(''^).
analyse
worst-case
the
complexity
algorithm which uses Fibonacci heaps runs
Consequently,
whenever log nC ^
runs in time linear
1.
i.e.,
of
semi-logarithmic model of computation.
time.
not O(n^'^0,
This model of computation assumes that arithmetic
on integers of length Odog n) has
e.,logC =
is
which arithmetic operations take time proportional
the integers they manipulate.
i.
all
C
model
the similarity assumption does not hold.
computation, which assumes that
if
of
our algorithms
In particular,
in
time
it
is
shown
0(m flog nC/log n1 +
algorithm runs in linear time (and hence
this
(log n)^
or
m > n log n/Vlog nC
.
in
that
the
our
n Vlog nC
is
optimal)
In particular, the algorithm
in the size of the data for all sufficiently large C.
One-Level Redistributive Heap and Dijkstra's Algorithm
In this section,
and we use
it
to
we
describe the Redistributive heap (abbreviated as R-heap)
implement
Ehjkstra's algorithm.
the help of a numerical example.
We
illustrate
heap operations with
Here we describe the one-level version
of the
R-heap, leaving the generalizations for the subsequent sections.
1.1.
)
Properties of R-heap
A
heap (or a priority queue)
each with a real valued
label,
is
an abstract data structure consisting of items
and on which the following operations can be
performed;
differs
and find-min.
create, insert, delete,
from
heap
a
denoted by the
Min(d) = min
{d(j)
nodes with
A node
j
is
added
to the
deleted from the heap
is
:
stores
The R-heap
set T.
distance label and
few ways that are particular
in a
Dijkstras algorithm
The R-heap
e T).
a data type that
to the operations
heap when
for
labels,
gets a finite temporary
it
pennanently labeled
is
it
needed
temporary distance
finite
when
is
The implementation of the R-heap takes advantage
Let
of the
following two properties that are true for Dijkstras algorithm
Each
LL
Integrality Property.
L2.
Monotonicity of minimum.
A
have
K
suitable choice
=
+ [log
1
Cl
of
mterval ^f integers
[/j^
We
,
We
is
subsets of nodes,
and upper
We
limits of range(k)
refer to
width of bucket k
I
to
range
it
may be
easier to
temporary distance labels
bucket k
if
properties,
Rl.
be
,
this
(/q
<
are denoted by
'k
l^
and
^ "k
uj^
are
^^^^ *^^
'
The ranges
If a
node
as fixed.
heis a finite
j
We
store
Node
i
always
nodes with
will
finite
be stored
temporary
/j^
then dd]) <
.
j
<
In other words,
k,
and
label,
then
if ij
e
and k are both nonempty,
CONTENTS(j), ii e CONTENTS(k),
if
buckets
j
d(i2).
Continuity property'.
TTie
union of
all
ranges
is
in
satisfy the following
,uk].
If
.
of buckets
assignment uniquely defined.
Monotonicity Property.
u:
we
nevertheless, for the following
TTie ranges of the buckets
.
buckets.
as the width of bucket k
I
.
R-heap as follows:
in the
uj^]
Range property.
then
R3.
[/j^
which makes
d(j)6
R2.
d(i) e
view the ranges
If
.
(k)
The
2*^"^
change dynamically throughout the algorithm;
discussion,
called
k a (possibly empty) closed
which we denote by rangeik).
uj^]
maximum
K
associate with each bucket
considered to be empty.
define the
+
1
k = 0,l,...,K, the nodes in bucket k
respectively called the lower
range
does not decrease following a deletion
For our implementation of Dijkstras algorithm,
K.
For
CONTENTS(k).
the set
Min(d)
R-heap consists of
single level
some
integer.
is
node from the R-heap.
of a
for
label d{i)
a closed interval
[/q
,
uj^].
;
The ranges
These properties will be necessary
much
The width
Redistributivity property.
bucket
most the sum
at
is
in
later.
of bucket
is 1.
maximum width
of the
properties.
however, their use
work;
for the algorithm to
the algorithm will not be apparent until
R4.
two additional
of the buckets also satisfy the following
The width
of buckets
of the k-th
through k-1,
foraU k=l,...,K.
R5.
Last bucket property.
In our algorithms, the
range(O) =
Note
exposition,
distance label
We
[2^-'^
,
2^-1]
«
is
which
If
d(i)
=
«
If
d(i)
<
« and
,
assume
k=
K.
1
width of bucket
K+1
K
is
^
2'^°S
which contains
all
'
^ C. For simplicity of
nodes whose temporar)'
.
associate with each
We
.
of the buckets are as follows:
ranges
for
,
also create a bucket
indicates the bucket to
(see, for
initial
maximum
that the
we
I
]
[
range(k) =
C
rangeCK) S
I
node
is
it
i
e
H
,
in the
H
heap
an index
K+
then assign(i) = (k
:
i
€
CONTENTS(k)).
that the contents of each bucket are stored as a
example, Aho, Hopcroft and
Dijkstra's Algorithm Using
We
UUman
[1974]).
:
returns a
Heap Operations
K
new empty heap
+
1.
H
doubly linked
list
Accordingly, each insertion and
perform the following operations on an R-heap.
INTTIALIZE(K, H)
which
1.
deletion from buckets take 0(1) steps.
1.2.
assign(i)
assigned.
assign(i) =
then
i
with buckets
: :
:
REINSERKi, H)
node
reinserts
contains
node
deletes
FIN'D-MCS'(i, H)
returns a
The following
i
from the heap.
node
all
i
nodes
a description of
is
bucket whose range
d(i).
DELETEd, H)
among
in the
i
such that
in
d(i) is
minimum
H.
Dijkstra's algorithm that uses the
above
heap operations.
algorithm DIJKSTRA;
begin
IN'ITIALIZE;
T*
while
do
begin
FIND-MIN(i, H);
T:
= T-(i);
DELETE
(i,
for each
(i, j)
H);
e A(i)
do
begin
d(j):
if
=
d(j)
min
{d(j)
= d(i) +
,
Cij
d(i)
+
Cjj);
then REINSERTC), H);
end;
end;
end;
1.3.
The DELETE and REINSERT Operations
The procedures INITIALIZE, DELETE, and REINSERT are
and are given below.
The procedure FIND-MIN contains the
deferred to after the numerical example.
all
straightforward,
redistribution
and
is
;
;
Procedure INITIALIZE;
begin
=
T:
N;
=
d(s):
and
,
C: = maxlq:
K: =
(i, j)
:
+ [log C1
1
range(O): =
for k
d(j);
:
=
{
to
1
:
=
to
1
«
for all
N - (s);
e
j
e A)
;
)
K do rangeCk)
CONTENTS(O): =
for k
=
{q)_;
:
= [2^-1
]]
.
^
K do CONTENTSC k
CONTENTS(K+l): =
^k .
N-
(s)
)
=
:
;
;
assign(s): = 0;
= K+1, for
assign(j):
all
j
N-
e
{s};
end;
procedure DELETE(j, H);
begin
k =
assign(j);
:
CONTENTS(k): = CONTENTS(k) -
{j)
;
{j}
;
end;
procedure REINSERKj, H);
begin
k =
:
assign(j);
CONTENTS(k); = CONTENTS(k) while
d(j) e
range(k) do k
:
= k-
CONTENTS(k): = CONTENTS(k)
assign(j)
:
= k
1;
u
(j);
;
end;
It
follows from properties L2, Rl, and R3 that the
succeeds in putting the node in an appropriate bucket.
REINSERT procedure always
We
illustrate
example given
its
in
R-heap and the heap operations on the shortest path
the
Figure
1
below.
In the figure, the
number beside each
arc indicates
length.
5
source
1.
The
and
K
Figure
For
E>ijkstra's
The
initial
buckets:
this
problem,
algorithm
R-heap
is
is
C
= 25
d(l) =
presented
in
,
shortest path example.
=
1
and
Figure
2.
+
flog 251
d(i)
=
«=
=
6.
The
for each
starting solution of
i
e
(2, 3, 4,
5,
6)
.
REINSERT
is
called to place
appears in Figure
buckets:
them
in the right buckets.
The R-heap
at this point
3.
4
5
6
7
(8,15]
(16,31]
[32,63]
[~]
(2,4)
(5)
{61
10
Lemma
D
Let
1.
The time spent
Proof.
number
be the
w
cumulative time spent
each
in
node
in the index assign(j) of a
any node
for reir\sertion of
from K+1
to
N
e
j
0(K), since
is
The cumulative running time
.
We now
FIND-MIN
consider the
nonempty bucket with
identify the
0(K) steps using
total
in the
time spent in the while loop
decreases monotonically
+ nK).
Q
In this operation,
we
therefore,
,
the
one, leads to a decrease
last
tissign(j)
minimum
R2).
p ^ 2
,
If
among
distance label
If
operation.
the lowest index.
a sequential search of
lowest-index nonempty bucket.
to
0(1) plus the time sp>ent
is
by one. Thus the
j
Then
nK).
0(D
is
The FIND-MIN Operation.
1.4.
and
REINSERT
call of
0(D +
is
Each repetition of the while loop, except the
while loop
REINSERT.
of calls of the procedure
REINSERT
all calls to
the buckets.
p =
or
1
is
accomplished
easily
bucket p
Let
in the
heap
we may have
be the
properties R4
(from
then bucket p contains a node with smallest distance
determine that node
in
then any node in bucket p has the
,
nodes stored
all
This
first
to scan the entire contents of
but
label;
bucket
p.
This
time bound would be 0(n) in the worst case, and hence totally unsatisfactory for our
However, we can do
purposes.
observation
If
:
p ^
2
the lowest-index
is
property L2 that the ranges range(O),
We
storing temporary labels.
buckets
As we
0,
.
.
.
,
p -
1
.
.
.
,
range(p -
and REINSERT the nodes
0(m
our example and then generalize
example given
The buckets
The range
of bucket 4
0,
.
.
.
,
based on the following
nonempty bucket, then
1)
will
it
+ nK).
We
is
crucial to
first illustrate
into the
in these buckets
overall
the redistribution on
subsequently.
in
Figure
3
are empty, and the union of their ranges
is [8, 15],
(9, 15)
follows from
improve the
4,
bucket 4
is
the lowest index
nonempty
is
but the smallest distance label in this bucket
property L2, no temporary distance label will ever be less than
redistribute the range
it
never be used again for
CONTENTS(p)
of
shall see later, this redistribution of ranges
In the
is
can thus redistribute the range of bucket p
complexity of our algorithm to
bucket.
The improvement
better.
9.
We
(0,7).
is 9.
By
therefore
over the lower indexed buckets in the following manner.
1
,
1
range(O) =
[9]
ranged) =[10],
range(2) =[11,12],
rangeO) =[13,15],
=
range(4)
e
.
All other ranges
do not change.
The range
of bucket 4
contents of bucket 4 must be reassigned to buckets
by successively
REINSERT
calling the
through
3.
is
now empty, and
This
is
accomplished
The resulting contents
procedure.
the
of the
buckets are as follows:
CONTENTS(O)
=
(5)
,
CONTENTS(l)= 0,
CONTENTS(2) = e
,
CONTENTS(3) =
(2, 4)
CONTENTS(4) =
,
.
This redistribution necessarily makes bucket
FIND-MIN
k
we
k.
with k > 2
property R4
If
,
is
k can always be done and
The
into buckets
In principle,
node
is
in
O(nK).
satisfied,
.
.
,
.
.
.
,
k-
however,
in
all
This
FIND-MIN
is
why
1
.
This procedure consists of
and then reassigning
k
nodes can be reinserted
it
is in
our reinsertion step
FIND-MIN
The
operation
the lowest-index
any of the n
we
total
is
different
FIND-MIN
are reinserting each scanned
at
node
nonempty bucket.
most
K
node
different
time spent in scanning nodes
is
redistribution of ranges reduces the running time so
dramatically.
A
the nodes of
in the appropriate buckets.
Thus each node can be scanned
operations.
all
then the redistribution of the range of bucket
could be scanned in
j
into a lower index bucket.
times
.
scanned whenever
any node
operations;
j
its
,
,
potential bottleneck operation in the
A
scanning.
nonempty bucket,
redistribute the range of the lowest-index
modifying the ranges of buckets
bucket
and the
operation then returns node 5 as the node with smallest distance label.
In general,
say, bucket
nonempty,
formal description of the
FIND-MIN
operation
is
given below.
;
;
12
procedure FLVD-MIN(i, H);
begin
k:
= 0;
CONTENTS(k)
while
p:
do
=
= k +
k;
1;
= k;
iipg
(0,
1)
then
begin
d^^:
= min(d(j)
range(O)
Up be
let
if
=
:
p=K
for
{
:
j
d^in
e
)
upper
the
CONTENTS(p));
limit of bucket p;
then
k;
=
ltoK do
=
ltop do
e
CONTEN'TS(p) do REINSERT^,
rangeCk): =[
2^^-''
+ d^^j^
2l<
,
+
d^j^^j^
+
1
]
else
for
for each
k;
j
2k-U
range(k):=l
dn^i^
,
min(2l^ + dn^j^-1. Up)];
H);
end;
CONTENTS(O) *
if
then return any node
return any node
else
i
€
i
€
CONTENTS(O)
CONTENTS(l);
end;
Accuracy and Complexity of the Algorithm
1.5.
Theorem 1.
Dijkstra's
algorithm
R-heap determines shortest paths from node
implemented
s to all
using
one-level
n log C)
a
0(m
other nodes in
+
steps.
The algorithm
Proof.
correctness
it
suffices to
is
an implementation of
show
that the
R-heap
EHjkstra's algorithm
Suppose inductively
first
R1-R5 are
that the properties
affect the properties
d(j)
is
R2-R5, but can
show
its
label.
This amounts to
throughout the algorithm.
R1-R5 are
that properties
consider an operation in which
does not
satisfied
to
correctly stores the temporar)- labels
and correctly determines the minimum temporar)- distance
showing
and
decreased.
affect
Rl.
satisfied at a given step.
We
Decreasing a distance label
Let
node
i
be the node with
13
Then
smallest distance label at this iteration.
upon whether node
was
i
from the R-heap. Note
Iq
<
d(j)
<
uj,^
Now
in
bucket
FIND-MIN
consider a
and
Note
h <
that
k =
range of each bucket
amount
h
1,
-I-
.
.
.
I^K
d(j)
'
=
Cjj
d(j)
^
d(i)
S
Iq
deletion
Hence,
.
satisfied.
nonempty bucket
p = K, then the
ranges by the amount dj^jj^,
in this step.
initial
they
will
/_
0,
+
I
range
(p)
I
-
1
If
R2-R5.
satisfy
< /p + 2P~^ £ <^min ^
l,...,h-l, isa
is
[
^^^
If
^^ "^^
•
by the
translation of the initial range
2"'^ + dj^jj^
Up
,
];
the ranges of buckets
It is
easily verified that
FIND-MIN
next note that modification of ranges in the
moves each node
Now,
+
its
ranges satisfy properties R2-R5.
We
above, the
depending
respectively, prior to
are empty; and other buckets are unaffected.
p
,
,
step in which the ranges of buckets are modified.
dj^^^; the range of bucket h
new
these
u- =
p, since
1
be the least-index bucket for which 2"~^ + djj^jp > Up.
bucket h
let
or d(i) = /q +
Iq
1,
d(i)
hypothesis
inductive
the
p < K, then
^
buckets are translated from their
all
by
C
+
1
and property Rl remains
,
Let bucket p be the lowest-index
ranges of
or bucket
uj^ ^ /q +
that
=
d(i)
in
new range
bucket p
to a
of bucket p
lower index bucket.
empty and
is
when p = K.
its new range is
consider the case
'k + 2^
-
C
< dmin +
then
1],
If
[
all
of
its
step necessarily
p < K, then, as observed
If
nodes move
to other buckets.
the previous range of bucket
d^jn
+ 2^-1
< di^in + 2^'^, during reinsertions
all
,
dmin
nodes
+ 2^
in this
-
1].
bucket
K was
Since
move
to
lower index buckets.
we
Finally,
is
performed
operation
procedure
FlND-MlN
first
p
1
is
most
,
it
m
n times.
I
procedure
reinserts each
can happen
at
most
distance labels
is
K
to
0(m
node
j
€
).
I
+ n log K)
either of bucket
cumulative time.
found
The
be
requires
0(K) time
to
update the ranges of buckets.
This effort
is
If
Otherwise, the
The time needed
0( CONTENTS(p)
is
The REINSERT
time.
to
0(1) time.
nonempty bucket and
in total.
0(1)
The DELETE operation
times because of the modifications of distance
requires
called
this call takes
bounded by O(nK)
bucket
at
Lemma
by
nonempty then
find the
and each execution requires
n times
performed
is
labels and,
analyze the complexity of our algorithm.
call
or
1
is
to find the smallest distance label in
However,
CONTENTS(p)
subsequently,
to a
the
REINSERT
lower index bucket, which
times for any node. The total time needed to find the smallest
thus
bounded by
O(nK).
This also implies that
FIND-MIN
14
REINSERT
operation calls
As K
time.
=
1
+ flog Cl
,
the theorem follows.
The Two-level Redistributive Heap and
2.
In this section,
O(nK) cumulative
O(nK) times, requiring
operation
we
Dijkstra's Algorithin
present a generalized version of the redistributive heap
discussed in the previous section which uses a two-level bucket system instead of
We show
one-level bucket system.
implement
that the two-level bucket
0(m
Dijkstra's algorithm in
< 3
can be solved
at least as fast as
in
0(m)
time.
Fredman and
asjTnptotically faster
whenever
Under
We
+ n log C/log log C) time.
C
eissume, without any loss of generality that
C
system can be used
S
4,
=
since the shortest path problem with
the similarity assumption, this algorithm runs
and
Odog
n).
Properties of Two-Level R-heap
2.1.
The two-level
bucket
is
(or two-echelon)
further subdivided into
union of the ranges of
union of the contents
k as the subbucket
and L =
3
is
L
(small) subbuckets.
of its subbuckets.
(k,
R-heap consists of
K
(big) buckets,
The range
An example
h).
given in Figure
We
refer to the h-th
of an
and each
of a bucket
subbuckets and, similarly, the contents of
its
a
bucket
is
the
is
the
subbucket of the bucket
empty two-level R-heap with K =
3
5.
Bucket range
Buckci
span
Bucket
Subbucket
Subbucket
range
Subbucket
[0]
[1]
[2]
[3.5]
16.8]
[9.11]
[12.20]
[21
.
29]
[30, 38]
span
1
3
1
Figure
5.
An
to
subsequently
Tarjan's implementation of Dijkstra's algorithm
m/n
a
3
9
3
empt)' two-level R-heap with
K
9
9
= 3 and L =
3.
is
;
,
1
In the one-level bucket system, the range of a bucket
Thus the maximum width
of the previous buckets.
maximum
the
v^idth of the
range of a subbucket
is
k-
first
redistributed over
all
of bucket k
of
This allows us
of the previous buckets.
to select
much
buckets.
For example, to store the distance labels
and leads
larger width of buckets
most the sum
is at
all
In the two-level bucket system, the
buckets.
1
redistributed over
is
to a reduction in the
range
in the
[0
number
of
38], the one-level
,
bucket scheme uses 7 buckets, whereas the two-level bucket scheme given in Figure 5
uses only 3 buckets. Further, once the bucket containing a node
determine the appropriate subbucket in 0(1) time
and
subbuckets
This speed of insertion into the
.
number
the reduction in the
detennined,we can
is
of buckets
translated into an
is
improved complexity bound of the algorithm.
The algorithm suggested
division by powers of
powers
by
k
of
2.
K and L
in this section also
We
.
assume
both
that
K and L
are appropriate
This allows us to perform multiplication and division more efficiently,
shifting the binary representation of a
is
performs multiplication and
a closed interval of integers
maximum width
of bucket
k
[l^
,
number. As
uj^]
which
defined to be
is
the buckets satisfy the properties
earlier, the
we denote by
Rl, R2, R3, R5,
k=
range
The
(k).
The ranges
of
and the following modification
of
for all
L*^
range of the bucket
1,
.
.
.
,
K.
R4.
The width
Redistributivity Property.
R4'.
width of a subbucket
the buckets
The
initial
1
in
bucket k
through k-1
,
is
for all k
of each subbucket in bucket
at
=
most the sum
2,
.
.
is 1.
maximum
The
width of
K.
,
.
of the
1
ranges of the buckets are given below.
ranged) = [0,L-1];
[L,L + l2-1];
range
(2)
=
range
(3)
= [L + L^
,
range (K) = [L + L^ +
where
K and L
Appendix
are
many
that
K
L + L^ + L^ -
.
.
.
+ L^-1
,
1]
L + L^ +
.
.
.
+ L^-^ + L^]
are positive integers chosen so that
= L =
1
L*^"^ ^ C.
We show
in the
+ [2 log C/log log Cl satisfies this condition. Clearly, there
other choices of
K and L which
also satisfy the
above condition, but
5
;
.
16
setting both equal to
+ [2 log C/log log C1 apj^ears
1
we
For the sake of convenience,
structure
nodes with temporary distance
We
subbucket.
K
create a bucket
label equal to
•»
above ranges as
refer to the
be a good choice for our data
to
we
represent the
The range of
bucket
a
range of a subbucket
initial
(k,
h)
is
range of bucket k by
o
[U
denoted by the interval [I^
and upper
are respectively called the lower
all
For
ranges in this section
initial
u
,
.
]
partitioned into the ranges of
is
which contains
1
This bucket has exactly one
.
o
simplicity,
+
u^y^]
,
The
.
subbucket
limits of the
of subbuckets satisfy the following property for every k =
1,
.
.
and
/j^
uj^^^
The ranges
(k, h).
K.
,
.
The
subbuckets.
its
Subbucket property.
R6.
L
range
(i)
(k)
LJ range
=
h =
(iii)
I
< h and the subbuckets
r
if
(ii)
range
We
(k,h)
l
(1,
h)
=1,
I
for each h =
store the ranges of
the
number
k =
1,
.
.
.
few subbuckets
The range
the following rule:
subbucket
ej^
+
1-
,
.
the
[/j^j^
is
numbers
nonempty, then uj^ < /j^
The ranges of
as needed.
may
;
and
subbuckets are
its
Chje to the redistribution
be empty. The index
of the bucket k.
divided over
in the
its
Initially,
represents
ej^
=
ej^.
0,
for each
nonempty subbuckets using
range
[l^
,
uj^
is
are given to the
]
are given to the subbucket
of a subbucket (k, h)
uj^^]
,
are
L.
numbers
L'""'
the next L*""^
Consequently, the range
.
efficiently
of a bucket k
first
.
of a bucket
empty subbuckets
of such
K.
,
1
(k, h)
buckets explicitly.
maintained implicitly and computed
of ranges, the first
and
(k, r)
+
ej^
2,
and so on
given by the following
expressions:
/;j,
= /l,Mh-ei,-l)Ll^-l;
"kh = "^^
If
l^Y\
{'k
> "k.h
'
^^^-
initial
integer
numbers and ranges
order.
The
bucket has
sufficient since the
>'
^^^^ ^^^ subbucket
buckets are given by the
last
L^"^ -
^k^
width of
all
a
"k
is
}•
considered to be empty.
ranges, the range of bucket
of
of
its
its
subbuckets consist of
subbuckets, except the
subbucket
in
bucket
k <
If
K
ranges of the
consists of
L*^"' integer
first
K mav be
as
one,
much
numbers
empty
as
L*^
This
L^~^
,
in
is
and
1
lK
^ c.
1
we keep
will be seen later that
It
this
property satisfied throughout the
algorithm.
We
We
subbuckets.
CONTENTS
in a
The contents
we
bucket
never need
belongs.
For example,
is
we
Further,
=
associate with
(k, h),
then
it
given below creates the
implies that node
how
the various heap operations
initial
R-heap.
R-heap.
procedure INITIALIZE;
begin
C: =
max
(cj:
and
:
(i,j)
d(j);
=
«
for each
j
€
N-
e A);
K:= 1+ r21ogC/loglogCl
;
L:= 1+ r21ogC/loglogCl;
o
o
rangeOi): =Ui^- Uj^l
set ej^
:
=
for
CONTENTS
= 0,
assign(i):
= (K +
card(k); =
end;
each
for
k:
0,1): =
assign(s):
=
/
each
CONTENTS(K+l,
card(l):
1):
=
1,
=
k:
.
.
.
.
.
,
K;
K;
,
.
1,
(s);
=
N-
(s);
1);
1, 1),
for each
i
e
l;
,
card(k)
i
number
the
and maintain
in the
i
of
to
is
R-heap a
which
in the
it
h-th
Two-Level R-heap
in
algorithm can be performed on a two-level
,
node
is
its
k.
describe
set d(s): =
set
the union of the contents of
What we need
this set explicitly.
assign(i)
if
Heap Operations
We now
k
by the
h)
(k,
which indicates the bucket and the subbucket
set, assign(i),
subbucket of bucket
2.2.
of a bucket
which we represent by the cardirulity index
k,
throughout the algorithm.
two-tuple
temporary distance labels in appropriate
finite
represent the contents of the subbucket
(k, h).
subbuckets, but
nodes
nodes with
store
for each k = 2,
.
.
.
,
K;
N - (s);
(s);
needed
The procedure
in
Dijkstra's
INITIALIZE
7
18
INUIALLZE
Clearly, the procedure
operation
takes
0(n
-t-
and
as easy as in the one-level bucket system,
is
K) time. The
is
DELETE
given below.
procedure DELETE(j, H);
begin
(k, h);
= assign(j);
CONTENTSCk,
=
h):
card(k): = card(k) -
CONTENTS(k,
h) -
(j);
1;
end;
The procedure REINSERT(j, H)
its
is
also similar.
present subbucket, then by scanning the buckets
range includes
includes
d(j)
Then,
d(j).
and add node
j
in
If
node
j
is to
we determine
be
moved from
the bucket
whose
we determine its subbucket whose range
contents. A formal description of this procedure is
0(1) time
to its
given below.
procedure REINSERT(j, H);
begin
(k, h):
= assign(j);
if d(j) i
range(k, h) then
begin
CO\TEN'TS(k,
=
h);
CONTENTS(k,
h) -
(j);
card(k): = card(k)-l;
while
r:
d(j) «
range(k) do
k:
= k-l;
= L(d(j)-/i,)/L'^-''j+ei,+ l
assign(j):
=
(k, r);
CONTE\'TS(k,
r):
= CONTEN'TSCk,
card(k): = card(k) +
r)
+
(j);
1;
end;
end;
Lemma
0(D
2
In the iwo-level
R-heap
,
D
calls of the
procedure
REINSERT
take
+ nK) total time.
Proof.
Each execution
spent in the while loop
of the
REINSERT procedure
takes
0(1) time plus the time
Each iteration of the while loop moves a node to
a
smaller
1
K
index bucket. As there are
0(D
D
buckets,
procedure would take
calls of this
+ T\K) overall time.
The procedure FINEVMIN
is
described below, followed by
its
explanation.
procedure FIND-MING, H);
begin
k:
=
l;
do
while card(k) =
p:
= k and
h:
=
+
ej^
=k+
k:
1
;
while CONTENTSCp, h) =
if
p>
1;
do
h:
=h+
1;
then
1
begin
dn^ir,:
if
= min{d(j):
j
CONTENTS(p,
e
h)};
p = K then
for k; =
1
p do
to
o
o
range(k): = [l^ + d^^^^
u^
,
+
d^^] and
e^.
=
0;
else
begin
Upj^ be the
let
for k; =
1
to
p-
upper
1
limit of the
o
range(k): = [1^ +
[
(p, h);
do
o
range(p): =
subbucket
d^^^ min (Up + d^^,
Up^ +
,
1
/
Up] and ept =
u^^]] and
e^r.
=
0;
h;
end;
for each
h:
=
j
CONTENTS(p,
e
h)
do REINSERTCj, H)
;
l;
end;
return any
node
i
€
CONTENTSd,
h);
end;
FIND-MIN
The procedure
nonempty bucket
p.
subbucket
is
(p,
respectively.
h)
If
proceeds by determining the lowest-index
Next, by scanning
identified.
p =
1
,
its
subbuckets, the lowest-index nonempty
These two steps require
then every node in the subbucket
0(K)
(p, h)
and
0(L) time
has the smallest
9
20
distance label (by property R6
nodes
in the
subbuckel
translated by the
p >
1
then ranges of buckets are modified and
,
p = K, then the new ranges of buckets are the
If
amount
As
dj^jp.
Theorem
in
its
previous range.
redistributed over the buckets
(p, h) is
(Upj^ +
1,
and the
Up);
nodes
case, all
FIND-MIN
in the
first
subbucket
K
p -
to
1;
move
(p, h)
buckets, each
the range of bucket
that this keeps
K
of bucket
is
node
p
is
modified as
made empty.
In either
lower index buckets during
to the
scanned 0(K) times
is
called
Since
the calls
all
ranges
initial
p < K, then the range of the subbucket
If
The REINSERT procedure
steps.
equal amounts of time to execute
we
1
is
the nodes with smallest
h subbuckets of the bucket p are
Since there are
reinsertions.
moves
shown
makes the new range
distance labels to the subbucket (1,1), and
completely disjoint from
can be
1, it
Rl, R2, R3, R4', and R5 satisfied,
the properties
This arxalysis
are reinserted to lower index buckets.
(p, h)
divided into two cases.
If
(iii)).
K
0(m
+ nK) times and
in all
takes
it
= L = [2 log C/log log C1 +
1,
get the following result:
Theorem
0(m
Dijksira's aJgorithm implemented using a two-level R-heap runs in
2.
M
+ n log C/log log C) time.
empty
Finally ,we discuss the time needed to initialize the subbuckets as
C
is
computation
is
This initialization takes 0(KL) time, which could dominate the running time
In such a case, the semi-logarithmic
exponentially large.
more appropriate
initialization
as discussed in Section
is
selected for the
the initialization time
A
2.
first
time in a
we
if
a
the
is
FIND-MIN
operation
In this
way,
C<n
suggest an improved version of the algorithm described in
The improved algorithm runs
improvement
and using
we can reduce
dominated by the running time of the algorithm.
is
Further Improvement
In this section,
Section
Nevertheless,
of
if
time to O(nL) by postponing any insertion of a node into subbuckets of
bucket k until k
3.
5.
model
sets.
in
0(m
+ n log
C
/log log nC) time.
This
obtained by using larger numbers of subbuckets with each bucket
more
efficient
technique
to locate the first
nonempty subbuckel
of a
bucket.
This data structure consists of
subbuckets.
The value
of
shovNTi that the value of
K
K
is
K
buckets and
each bucket has
chosen so that (KLlog nj)^"'' ^
= flog
C/max(
C
It
K
[log nj
can be easily
log log C, log log n)l satisfies the
above
21
and log C/max
condition,
subbuckets with each bucket does not
the
cleverly as
We
Llog nJ bits,
whose
otherwise.
We
binary
We
number
We
i-th bit is
its
number
is
non-zero
1
number
n.
In the
groups of subbuckets,
bit in the selected
in order, to identify the first
group by a
the corresponding y value denotes the
we use
its
table-lookup.
first
nonzero
numbers
first
then scan
group whose
we
scan
binar)'
identify the
first
(x,
where
y)
bit in the
for all
number
its first
< x < n
1
For a given
x.
nonzero
bit (as y) in
DELETE and
0(m + nK) =
0(1) operations per
+ n log C/log log nC) time.
Implemer\tation Using Fibonacci Heaps
4.
We show
in
We
Consequently, the above algorithm runs in
operation.
we
step,
the
of groups of subbuckets can be easily
maintained with an additional overhead of
REINSERT
Thus
This consists of preparing a table
binary number (as x) in the table to find
Further, the binary
0(1) time.
non-empty, and
bucket.
Both of these steps take 0(K) time. Next,
nonzero.
is
FIND-MTN
nonempty
to identify the least-index
Uog nj
of
as the binary number of that group.
the beginning of the algorithm consisting of values
group,
K groups
the i-th subbucket in the group
if
an integer no more than
through the buckets
through
be p)erformed
to
group a binary number of
associate with each such
refer to this
is
depends
it
use the following technique to speed up
partition the subbuckets of a bucket into
subbuckets each.
0(m
time since
involves sequentially scanning the subbuckets of a bucket to find
it
index nonempty subbucket.
lecist
this operation.
at
affect the reinsertion
Using more
log nC).
on the number of buckets. However, the FIND-ME^ step has
solely
more
OOog C/log
(log log C, log log n) =
0(m
two-level
in this section that the two-level
+ n Vlog
method
C
)
time using a variant of Fibonacci heaps.
requires
0(m
nonempty subbucket which
improvement
bucket,
i.e.,
K
of a bucket.
consecutively
results
bucket system can be implemented
takes
0(L) time for each
it
M
first
step.
belongs.
This index
pointed out that the data structure
we
is
all
now
bucket system described in the previous section and
is in
its
Our
for each
the buckets)
the index of the
called the key of the node.
describe
first
nonempty subbucket
we number the subbuckets (of
= LK and associate with each node
For this purpose,
subbucket to which
FIND-MIN
from having a much larger number of subbuckets
through
that the
+ nK) time except for the step of finding the
< < L, and using Fibonacci heaps to select the
1
Observe
It
may
be
addition to the two-level
sole purpose
is to
identify a
22
node with smallest key which
subbuckel
in the
nonempty
equivalent to finding the least-index
is
above data structure
The Fibonacci heap (abbreviated
as F-heap) data structure
able to perform
is
the following operations efficiently:
find-min:
Find and return a node of
insert(x):
Insert a
new node
minimum
key.
with predefined key into a collection
x
of nodes.
Reduce
decrease (wlue, x):
node
the key of
from
x
current value to value,
its
which must be smaller than the key
Delete node x from the collection of nodes.
delete(x):
The Fibonacci heaps
in the
of
Fredman and Tarjan
find-min, insert, and decrease, and
Mehlhom
Odog
k) for delete,
These bounds are also attained by relaxed heaps due
We
V-heaps due to Peterson [1987].
M,
modify F-heaps so
many
i.e.
that the
we mean
worst-case sequence of operations.
a
discussion of this concept, see Tarjan [1985] and
larger than
support these operations
[1984]
(By amortized time
following amortized time bounds
operation averaged over
much
replacing.
is
it
For a thorough
[1984]
where
the time per
k
to E>riscoll
)
0(1) for
:
the heap size.
is
al
et.
[1987]
are interested in the case in which n
We show
items have the same key.
amortized time per delete
is
reduced
to
can be
below how
Odog min
(n,
without changing the 0(1) amortized time bound for the other three operations
the
two
level
this choice of
bucket system,
we
L and K assures
select
that
L =
2*^"^
C which
L*^"' ^
K
and
= fVlog
is a
C 1+1. Note
level R-heap.
0(m
+ nK) decrease operations and n delete operations in the algorithm.
a total of n insert operations,
above data structure, these operations take
0(m
+
logaK) = K-1 +
a total of
K
nNTogT
)
We now
discuss the modification of the F-heaps to
time, since
time per delete operation can be reduced
to
log
0(1) amortized time bound for the other operations.
that the
F-heap contains
at
most
M
items,
i.e.,
al
(n,
Mj)
For
that
n find-min operations,
0(m
= ©(VTogT
Odog min
to
necessary condition for the
two
There are
and
+
nK
Using the
+ n log (LK)) =
).
show
that the amortized
M)) without changing the
The main idea
is to
make
sure
most one item per key value.
23
Making
work
this idea
some knowledge
We
need
in the presence of decrease oi>erations requires
of the internal
know
to
is
Each node
key(x).
the following facts about F-heaps.
whose nodes are
a rooted tree such that
an F-heap
in
hais
fundamental operation on F-heaps
trees into
p(x)
if
F-heap consists of
the pwrent of
is
node
number
of
A
key(p(x)) <
x,
its
a
A
children.
which combines two heap-ordered
linking,
is
An
the items in the heaps.
a rank equal to the
one by comparing the keys of their roots and making the root with the
smaller key the parent of the root with the
smallest key,
larger key, breaking a
0(1) time. In an F-heap, a p>ointer
link of>eration takes
creating a
and
care
workings of F-heaps.
collection of heap-ordered trees
heajj-ordered tree
some
making find-min an 0(1) time
new one-node
tree
and adding
it
A
tie arbitrarily.
maintained to a tree root of
is
An
operation.
insertion consists of
to the collection of trees.
This also takes
0(1) time.
Each non-root node
unmarked.
it
When
F-heap
A
updated. Then,
parent p(x)
is
cut
y
is
by losing
x
if
or y
is
initial tree
it
is
marked.
containing x
The
is
marked per
and
is
most one cut per decrease operation, the
heap operations
is at
many
removing node
x,
cut, if the
one of which
is
Icist
node y
is
break the
is to
rooted
at x.
The
0(1) plus 0(1) per cut. Since at most one
total
number
for at
of cuts during a sequence of
cuts.
The fourth heap operation,
(x), x),
such
its
most twice the number of decrease operations, even though a
single decrease can result in
decrease(key
last
and
node becomes unmarked per cut except
since one
link,
performed as follows.
cut the arc joiiung y
a tree root,
into possibly several trees,
cut,
is
overall effect of a decrease operation
time required by the decrease operation
node
comparison during a
repeated, with y initially equal to
is
parent p(y), and replace y by (the old) p(y). After the
not a root,
marked or
states,
not already a tree root, the arc joining x
is
and the following step
unmarked
a
node x
decrease operation on a
is
(the old) p(x), until
one of the two
is in
a non-root
value of x
First the
its
an
node becomes
a
becomes unmarked.
and
in
which does not
making each
of
delete(x)
affect
its
key
ways described above,
(x)
is
done by
but makes x
children a tree root, and
linking trees having roots of equal rank until
Fredman and Tarjan showed
,
that
no two
when
the following invariant
is
tree roots
first
performing
a tree root, then
fir\ally
repeatedly
have equal rank.
rooted trees are manipulated in the
maintained: for any node
x,
rank
(x)
24
=
Odog
where
d(x)),
descendants of
rank(x)
A
x.
number
the
is
i
€
(1
Odog
the set
S(i) of
designated as the representative of
the
non-representatives,
items x with key(x) =
whose
grouped
are
The following
heap ordered
and
tree
0(1) for
item in
S(i) is
trees
kind
the
of
and
These trees are divided into two groups:
and
passive trees,
key
< key(x)
(p(x))
whose
roots are
every non-representative
invariant that
that
of
For each value
One
i.
heap-ordered
into
roots are representatives,
non-representatives.
root of the
number
the
All the items, both the representatives
S(i).
manipulated by the F-heap algorithm.
active trees,
is
n) for delete.
are ready to solve the problem posed earlier.
we maintain
M],
,
d(x)
simple analysis gives an amortized time bound of
find-min, insert, and decrease, and
Now we
and
of children of x
is
is
a
maintained throughout
the algorithm.
We
note the following important features of this representation:
representative of the
and the
number
total
nonempty
nodes
of
To
tree is a representative.)
minimum
tree root of
making
into a
x
whether the
representative of
any)
is
one-node
becomes
its
active.
Otherwise,
it
new
x
If
inserted
is
is
linking
is
if
more new
0(1) plus
perform the
same way
empty or
trees,
and the
S(value)
is
We
an active
in
tree,
an active
to the active
perform insert(x) by
x) as
0(1) per
cut,
not;
if
so, x
becomes the
described above, breaking
with the following change:
some other item
tree rooted at the
new
empty, then x becomes
a non-representative.
x
in S(key(x))
is
(if
representative
a representative.
Other new roots created by the cuts
trees.
Tlie total time required
including the time necessary to
by the
move
trees
peissive groups.
delete operation as described
performed only on active
repeatedly linked until there
We
the root of
maintain a pointer
x Weis a representative then
Further,
between the active and
We
we
perform decrease (value,
representative,
remains
is
during the decrease become the roots of active
decrease
is
which becomes active or passive depending on
tree,
which
We
S(i).
S(key(x)).
made
find-min,
facilitate
i
most M. (Every node
in active trees is at
the tree containing x into one or
moved from
minimum
key; thus find-min takes 0(1) time.
S(i) into
set
set S(i) of
the
is
at
trees.
That
most one active
is,
above, except that the repeated
active trees of equal rank are
tree per rank.
analyse the efficiency of the four heap operations in almost exactly the
as in
Fredman and Tarjan
(1984].
We
define the potential of a collection of
25
number
rooted trees to be the
We
contain.
(measured
potential
of trees plus twice the
number
of
define the amortized time of a heap operation to be
in suitable units) plus the net increase in potential
is
zero and the potential
heap of>erations the
total
An
is
0(1), since
is
A
initial
decrease
it
of
total actual time.
does not change the
by one and thus also has an
insert increases the potential
amortized time bound.
The
causes.
an upper bound on the
is
find-min
of a
it
actual time
its
always nonnegative. Thus for any sequence
amortized time
The amortized time
potential.
marked nodes they
operation resulting in
0(1)
cuts adds
k
0(1) - k to the potential (each cut, except for at most one adds a tree but removes a
marked node). Thus
a decrease takes 0(1) amortized time
we
if
regard a cut as taking
unit time.
Each link during
amortized time of zero,
spent during a cut
removing
node
a
OClog min
(n,
is
of
M)).
if
we
regard a link
O(log min
minimum
{n,
M))
eis
taking unit time.
as
,
The additional time
the potential increase caused by
is
key, since the
maximum
rank of an active tree
Thus the amortized time
of a delete
is
Finally, the cost of creating
desired.
by one and thus has an
a delete reduces the potential
empty
sets
S(i)
is
O(log min
0(M).
We
(n,
is
M)), as
have thus shown
the following result:
Theorem
Dijkstra's algorithm
3.
modified Fibonacci heaps runs in
The idea used
implemented using the two-level R-heap and the
0(m+
n yjlog
C
)
U
time.
here, that of grouping trees into active
as well as to V-heaps to give the
same time bounds, but
it
and passive
trees, applies
does not seem
to
apply to
relaxed heaps.
The Semi-Logarithmic Model
5.
Computation
of
we analysed our algorithms in the uniform model of
we assumed that arithmetic on integers in the range
In the previous sections,
computation.
[0
,
In particular,
nC] has cost 0(1).
semi-logarithmic
model
In this section,
of
we
computation.
analyse our algorithms under the
The bottleneck operation
in
the
straightforward analysis of our algorithms in the semi-logarithmic model of
computation
is
the comparison whether
d(j) €
range(k) during reinsertions.
slightly vary the algorithm so that this step can be
number
of bits of d(j)
performed by looking
and we obtain the improved time bounds.
at a
We
small
'
26
The exact definition of the semi-logarithmic model
given by the following
is
two assumptions.
Arithmetic and
Al
other RAM-operations
all
(index calculations, pointer
and
aissignmenls, etc.) on integers of length OClog n) have cost 0(1),
A2.
Remark:
In this model,
We
word
= 0(nOn)). (Alternatively,
C
log
we
numbers
store
we assume
Each array element
.
if
Let us
first
Odog
the indexes are
nC/log n1 = 0(n^^
')
;
which
Mm
let
n) in
more than one
range
in the
(0,
we
analyse the basic algorithm of Section
The accuracy
2^-1]. Since
this is
are forced to the assumption
We consider
1.
its
proof
omitted.
is
temporary distance
finite
the following
proved
of this version can be
and therefore
minimum
be the
(d)
,
assumption A2.
^^ ^^^ binary representation of Min
'^
^K-1
an integer
justifies
similarly to that of the original algorithm,
,
is
n) in length
alternative description of the algorithm.
nCl
Odog
larger than
(assumption Al) that indexing into these arrays has cost 0(1), and
only reasonable
flog
).
represent arc lengths and distance labels as arrays of length Fdog nC)/Rl
where R = Ldog n)/2j
that Flog
C = 0(2
that
(d), i.e.,
Oj €
and
label,
and Min
(0, 1)
K
Let
=
let
=
(d)
K-1
y
i
OLj
2'
As
.
before,
we have
buckets
0,
.
.
.
,
K
+
with
1
=
i
i
€
e
CONTENTS(O)
CONTENTS(k)
Min
iff
representation of d(i) and k
i
€
Mm
d(i) =
iff
CONTENTSCK +1)
(d)
the
is
d(i)
iff
(d),
<
< «, ^^_^
d(i)
maximal index
for
•
•
with
•
Pq
Pj(._-j
^^
*
the binary
<^k-l
k)
denote the k-th
can be computed
label d(j) as
in
an array
k = assign(j) for each
Then
bit(j,
k)
is
the table BIT,
V €
(0,
2*^-1]
bit in the
0(1) time.
d(j,
j
is
)
binary representation of
As already
of length flog
where BIT(v,
and each
j
indicated,
nC/Rl
of
e
[0,
j)
is
R-l],
number
the
d(j,
kp.
j-th bit in
The
table BIT
we
d(j).
We
We show
store a
number
stored as a pair (k^, k2) with
the k2-th bit in the
^^"^
= «.
CXir algorithm requires successive bits in the binary representation of
biii],
'
of
< k2 <
d(j).
that
Let
bit(j,
k)
temporary distance
R bits each. The index
R and k = k^R + k2.
can calculate this
bit
by using
the binary expansion of v for each
is
easily
computed
in
bnear time.
27
Then the k2-th
computed
number
in the
bit
by
in 0(1)
With these
k^)
d(j,
is
given by BIT(d(j, k^), k2) and
it
can be
a table look-up in the table BIT.
REINSERT and FIND-MIN
procedures
definitions,
can be
reformulated as follows:
procedure REINSERT
(j,
H);
begin
k = assign (j);
:
CONTENTS(k)
while
bit
k)
(j,
:
=
CONTENTS(k) -
=
and
aj^
k>0
CONTENTS(k) = CONTENTS(k)
:
assign(j)
:
(j);
do k: = k-l;
u
(j);
= k
end;
procedure FIND-MIN(i, H);
begin
do k = k +
while card(k)=
:
Min(d) <- min{d(
let cxj^_-j
for aU
j
•
€
•
j)
:
j
e
1;
CONTENTS(k));
be the binary expansion of Min(d);
cxq
CONTENTS(k) do REINSERT(j,
H);
end;
A
call of
FIND-MIN has
REINSERT. The
of
relabeling
0(m
flog
nC/log n1
Section
1
4.
Odog nC)
total cost of the calls to
cost
Theorem
cost
Under
is
)
We
summarize
the assumptions
worthwhile
Tarjan's algorithm
to
under
compare
this
nl+
this
model.
is
per
)
0(m
+ n log nC).
relabeling
step
M.
0(m flog nC/log
Theorem
4.
Thus
n1
-^
and
hence
the modification of the algorithm of
n log nC)
.
U
time with the running time of Fredman and
In Fibonacci-heaps every step involves the
comparison between two keys and hence has cost ©(flog M/log nl)
are at most
Finally, the
in:
Al and A2,
runs in time Oimflog nC/log
It is
REINSERT
OCflog nC/log n1
overall.
exclusive of the cost of the calls to
when
Dijkstra's algorithm with Fibonacci-heaps has
n log n Flog nC/log nl)
,
the keys
running time
which agrees with the time bound
of
(There does not appear to be any simple modification of the Fibonacci
28
heap data structure
improve running times under the semi-logarithmic model.)
to
However, the present implementation
is
also worth noting that
it
0(m flog
takes time
Thus the modification
model.
simpler and has smaller cor\stant factors
is
C/log n1)
to
of the algorithm of Section
1
It
read the input in our
optimal whenever
is
m S n log n.
We
bucket
Odog
log L =
l1 and
let aj^_-j
^
L and Min(d) =
subbucketCk, h)
if
(x^V
h =
pj^.-j
Note
.
As above, we
bit
k
d(i),
a
and k =
is
that the buckets are
subbuckets are numbered
LOog n)/2j
Then
.
above.
as
is
node
0,
i
T with
e
h = a^
;
or
if
d(i)
Min(d) <
maximal index with
the
numbered
We
assume
that log
same way
as
we computed
is
now
)
L divides
Ldog n)/2j
by DIGITCj,
k),
h);
CONTENTSCk,
card(k)
end;
:
k)
=
=
CO\TENTS(k,
a^.
and k >
DIGIT(j, k))
= card(k) +
aj^_-]
•
•
pQ
and
given below.
h) -
1;
:
=
1
(j);
do k = k :
.
Tben the
is a
k-th
the k-th digit in the binary expansion
card(k): = card(k)-l;
while DIGITCj,
*
•
can be computed in
= assign(j);
CONTE\TS(k,
^^_^
where each array element
begin
:
belongs to
d(i),
Pj^_-]
procedure REI\SERT(j, H);
h)
«»
i.e.,
through K-1 and for each bucket,
store label d(j) as an array d(j,
The procedure REINSERT
(k,
Let
follows:
<
to
through L-1.
number.
in the
ourselves
restrict
buckets
to
digit in the L-ary representation of d(j), represented
time 0(1)
we
be the L-ary expansion of Min(d),
clq
either Min(d) = d(i)
the L-ary representation of
nodes
of
In these algorithms each
index into such an array has
AT
assumption
of
spirit
The assignment
n).
K =riog nC/log
is
the
In
bits.
< Oj <
An
represented as an array of L subbuckets.
is
log L
turn to the algorithms of Sections 2 and 4 next.
1;
CONTENTS(k,
DIGIT(j, k))
u
(j);
29
The
REINSERT
total cost of all calls to
arithmetic in the relabel step
0(m
is
+ nK). Also, the
total cost of
©(mTlog nC/log nl). The procedure FIND-MIN
is
is
given below.
procedure FIND-MIN(i, H);
begin
k =
0;
:
while card(k) =
do k = k +
p = k and h = 0;
while CONTENTSCk,
:
:
p>0
if
1;
:
h) =
do h = h +
:
1;
then
begin
Min(d): = min{d(j)
let
all
h: =
j
j
e
CONTENTS(p,
h));
ctQ be the L-ary expansion of Min(d);
txj<^_i
for
:
e
CONTENTS(p,
do REINSERT(j, H);
h)
0(o;
end;
return any node
i
in
CONTENTS(0,
h);
end;
A
Thus the
call to
FIND-MIN
has cost
total cost of the shortest
to
L) exclusive of the costs of reinserting.
path algorithm
We select K = Flog nC/log n"l
L
0(K +
If
be the greatest power of 2 which
which value log L divides Ldog n)/2
is
J
less
;
than or equal to log nC/log log
r>)/2J
-^ either
otherwise L
log nC).
We
to
The algorithm of Section 2
n
runs
in
0((m
+ nK)
2'-(^°g
is set to 2'-'^°6
fi^gj^
OCmTlog nC/log nl + n log nC/log
,
KL].
Thus the
Hog KL/log nl)
nC
since each of the
n"|)
)
we use
total cost of all calls
about an additional cost of ©(Flog KL/log
Fibonacci-heap.
time
log nC/log log
Finally, for the algorithm in Section 4
[0
nC <
thus obtain the following result:
Oimflog nC/log nl +
domain
"^/^J
L)).
^g ^^^^^
nC and for
running time of the algorithm reduces
5.
©(mTlog nC/log n1 + n(K +
log nC/log log
case, the
Theorem
is
m
-i-
U
.
Fibonacci-heaps with the
to
nK
REINSERT
calls to
for the decrease
Further, each call of find-min has cost
increases to
REINSERT
brings
operation in the
0(logKL
Flog
KL/log nl
).
3
Since a find-min in a Fibonacci-heap requires
KL/log
of OCflog
0(m( Flog nC/log
K
= FVlog
n1 + flog KL/log n1
L = fV log nCl
log
and log L = LOog n)/2j
for log
nC
)
to
nC
log
for
It
.
< (log
nr
4.
Thus the
KL/log
+ n(K + log KL) flog
^ (log n)^
above expression reduces
cases, the
and each step has
steps
by the remark following Theorem
n1)
nCl and
Odog KL)
;
total cost is
We
nl).
K
and
a cost
select
= log nC/log n
can be easily verified that
©(mf^log nC/log n1 + n\'log nC
in
both the
We
)
thus
obtain the following theorem.
Theorem
We
i.e.,
6.
6.
The algorithm of Section 4 runs
in time
Oim\^hgnC/lognY nilognC].
g
conclude that the algorithm of Section 4
C
t n'°§ "
or
,
is
nC t
optimal whenever log
(log n)'"
,
m > n log n/Vlog nC.
if
Conclusions and Research Issues
We
problem,
have presented several new
all
based on
a
new
algorithms for the shortest path
efficient
we call
in 0(m
data structure which
simplest two-level version of this algorithm runs
The
a redistributive heap.
C/
+ n log
log log C) time
using the uniform model of computation, which improves on previous algorithms
under quite reasonable assumptior\s on the
be very
efficient in practice.
data.
In addition,
Preliminary testing indicates that
best other implementation of Dijkstra's algorithm.
algorithm uses Fibonacci heaps and runs in time
algorithm
In
is
it is
not as efficient in practice, but
it is
it
sufficiently simple to
is
comparable
A more complex
0(m + nVlogC)
.
version of the
Although
we have
also
considered
algorithms under the semi-logarithmic model of computation, and
In the case
similarity assumption, the semi-logarithmic
model
computation than does the uniform model.
realism, the semi-logarithmic
uniform model,
viz.,
small part of a large
the uniform
model
and so there
is
model
number without
when C does
to
an implicit
model allows the user
perform arithmetic operations more
we count
of
restriction of the
getting charged for using the
semi-logarithmic model of computation,
not satisfy the
added degree
In addition to this
to operate
on
whole number.
of computation, each arithmetic step counts as
no incentive
we have
better reflects current sequential
also avoids
the semi-logarithmic
this
asymptotically better in the worst case.
addition to the results mentioned above,
modified our algorithms appropriately.
to the
a
In
one operation,
efficiently.
In the
operations more accurately to
31
some
reflect that
arithmetic operations, such as multiplication by 2 or determining
whether an integer
multiplication by
This
the
log
last
C
3.
degree of
Under
= Q(n).
increasingly worse as
to solve the
are
linear
C
if
is
best reflected in
C
is
when
data
the
in
our algorithms appear
gets sufficiently large, then the time
proportional to the time to read the data.
relative efficiency of the algorithm for large
uniform model
time
of computation,
In reality,
gets large.
is
semi-logarithmic model
model
the uniform
C
problem
flexibility in the
algorithms
our
that
fact
odd, are inherently faster than other operations, such as
is
This improved
not and can not be captured by the
of computation.
Currently, under the semi-logarithmic model of computation, our algorithms
are linear time for a
wide range
of parameter choices.
whether the algorithm can be made
the most difficult case
The
is
redistributive
when C
an open question as
linear time for all p>ossible inputs.
satisfies the similarity
heap data structure
problems because of the assumption
monotonically nondecreasing.
It is
is
that the
would be
It
It
appears that
assumption.
not easily generalized to solve other
minimum
in the
interesting to
FIND-MIN
step
know whether
assumption can be relaxed, or whether the data structure can be used
problems as
to
is
this
to solve other
well.
Acknowledgements
We
thank Hershel Safer
suggestions.
The research
Presidential
Young
for a careful reading of the
of the
first
and
Investigator Grant
third authors
paper and
was supported
many
useful
in part
by the
8451517-ECS of the National Science
Foundation, by Grant AFORS-88-0088 from the Air Force Office of Scientific
Research, and Grants from Analog Devices, Apple Computer, Inc. and Prime
Computer.
The research
of the
Sonderforschungsbereich 124, TPB2.
second author was supported by Grant
The research of
the fourth author
supported by National Science Foundation Grant No. E>CR-8605962
Naval Research Contract No. NOOOl 4-87-0467.
was
DFG
partially
and Office
of
—
32
Appendix.
Lemma
1.
Proof.
We
Case
1
1.
-^
1
<
log log
j
prove
C
C 2
log log log C,
For these values of C, log log log
.
1.
by simple case analysis.
this result
< 2^
C ^
for all values of
C
<
and the inequality
1
holds.
Case
2'^
2.
<
C
Hence
Case
< 2^ ^
For these values of C, ^ log log
.
the inequality
C>2l^. For €
3.
= 2^^
r
values of C, - log log
Lemma
Proof.
2.
Let L =
Shouing
'^^
^^
L*^
L log L > log
^
still
C
^
is
C
.
log log
C
= log log log
C
dominates
Then L^ ^
1
and log log log C <
=
2.
For
all
D
log log log C.
C
for all values of
higher
C ^1.
equivalent to showing that
21ogC
C. Substituting L='j
(2 log
C/log log C) log
=
(2 log
C/log log C)
(2
^
holds.
L log L =
>
C
log
[1
—
(2 log
j
t= in
C/log log C)
+ log log
C - log
Therefore, L log L > log
C
.
log log C]
^y Lemma
C/log log C) 2'°6 ^°§ ^
(
the left-hand side,
I
1).
we
get
2.
33
REFERENCES
Aho, A. V.
Van Emde,
Denardo, E.V., and
and Buckets. Oper.
Dial
Comm.
ACM
Dial, R.,
1959.
Mathematics
1,
An
R.,
J.
10, 99-127.
Shortest-Route Methods:
1.
Reaching, Pruning,
Shortest Path Forest with Topological Ordering.
360:
Kamey, and
D. Klingman.
1979.
and Labeling Techniques
for
A
Computational Analysis
Finding Shortest Path Trees.
A Note on Two
Problems
in
Connexion with Graphs. Numeriche
269-271.
H. N. Gabow, R. Shrairman, and R.
E. Tarjan.
1987.
Relaxed Heaps:
Alternative to Fibonacci Heaps, Technical Report, CS-TR-1 09-87, Department of
Computer
Science, Princeton University, Princton, NJ, submitted to
Fredman, M.L.,
and
R. E. Tarjan.
ofComp.
Sci.,
Gabow, H.N.
31
,
Gilsinn,
338-346, also in
1985.
/.
of
ACM
Comm. ACM.
Fibonacci Heaps and Their Uses in
1984.
Improved Network Optimization Algorithms.
Sci.
Design and Implementation of an
1977.
215-248.
,
Dijkstra, E.
Driscoll,
Sys. Theory
MA.
Reading,
E. Zijstra.
The Design and Analysis of
1974.
12, 632-633.
of Alternative Algorithms
Networks 9
Ullman.
27, 161-186.
Res.
Glover, D.
F.
and
B. L. Fox. 1979.
Algorithm
1969.
R-
R. Kaas,
Queue. Math.
Efficient Priority
J.D.
Addison-Wesley,
Computer Algorithms.
Boas,P.
and
Hopcroft,
J.E.
,
25th Annual
IEEE Symp. on Found.
34(1987), 596-615.
Scaling Algorithms for
Network Problems.
].
of
Comp. and
Sys.
148-168.
J.,
and
C. Witzgall.
1973.
A
Performance Comparison of Labeling
Algorithms for Calculating Shortest Path Trees.
Bureau of Standards, Washington, D.C.
Technical Note 772,
National
34
Glover,
D D
F.,
N. V. Phillips, and R.
Klingman,
Schneider. 1985
F.
Pol)T>omial Shortest Path Algorithms and Their Computational Atttributes.
Set 31,
New
Man.
110^1128.
Johnson,
D
.4CM24,
1-13.
B
1977a
Johnson, D. B
Allerton
Efficient
1977b.
Algorithms for Shortest Paths
Efficient Special
in
Sparse Networks
Purpose Priority Queues.
Proc. 15th
/.
Annual
Conference on Comm., Control and Computing, 1-7.
Johnson, D.
A
1982.
B.
Priority
Queue
in
Which
Initialization
and Queue
Operations Take OClog log D) Time. Math. Sys. Theory 15, 295-309.
Mehlhom,
Pape, U.
1984.
K.
1980.
Data Structures and Algorithms. Vol.
Algorithm
562:
Shortest Path Lengths.
Springer Verlag.
1,
ACM
Trans. Math. Software
6,
450-455.
Peterson, G.
A
1987.
L.
Balanced Tree Scheme for Meldable Heaps with Updates.
Technical Report, GIT-lCS-87-23, School of Information and Computer Science,
Georgia Institute of Technology, Atlanta, GA.
Tarjan, R. E.
6
1985.
Amortized Computational Complexity. SIAM
].
Alg. Disc. Math.
30^318.
Williams,
]
.W.
J.
G 11 7
1964.
7 B
Algorithm
232:
Heapsort. Comm.
/iCA'f 7,
347-348.
Date Due
DEC
SEP-
2 7 19^8
2^ \993
•tV.
Ftd
5
t995
2 y 199^
Lib-26-67
MIT LIBRARIES
3
TDfiO
DOS 35a TDS
Download