You are on page 1of 2

IEOR 266

Lecture 11

Network Flows and Graphs

October 12, 2008

Shortest paths (continued)

1.1

Dijkstras Algorithm (continued)

Theorem 1 (The correctness of Dijkstras algorithm). Once a node joins P its label is the shortest
path label.
Proof. At each iteration the nodes are partitioned into subsets P and T . We will prove by induction
on the size of P that the label for each node i P is the shortest distance from node 1.
Base: When |P | = 1, the only node in P is s. It is correctly labeled with a distance 0.
Inductive step: Assume for |P | = k and prove for |P | = k + 1.
Suppose that node i with d(i) = min{d(j) : j T }, was added to P , but its label d(i) is not the
shortest path label. Then there should be some nodes in T along the shortest path 1 to i. Let j
be the first node in T on the shortest path from 1 to i. Then the length of shortest path from 1
to i = d(j) + cji . Since d(i) is not the shortest label, d(j) + cji < d(i), and since cji is positive, we
have d(j) < d(i). This contradicts that d(i) is the minimum of d(j) T .
We next prove two invariants that are preserved during Dijkstras algorithm execution.
Proposition 2. The label for each j T is the shortest distance from s such that all nodes of the
path are in P (i.e. it would be the shortest path if we eliminated all arcs with both endpoints in T ).
Proof. We again use induction on the size of P .
Base: When |P | = 1, the only node in P is s. Also, all distance labels are initialized as follows:
d(j) := csj for all j A(1). Thus the labels are indeed the shortest distance from s, using allowing
only the path (s, j).
Inductive step: Assume for |P | = k and prove for |P | = k + 1.
After a node i in T is labeled permanently, the distance labels in T \ {i} might decrease. After
permanently labeling node i, the algorithm sets d(j) = d(i) + cij if d(j) > d(i) + cij , for (i, j) A.
Therefore, after the distance update, by the inductive hypothesis, the path from source to j satisfies
d(j) d(i) + cij , (i, j) A s.t i P . Thus, the distance label of each node in T \ {i} is the
length
Sof the shortest path subject to the restriction that each every node in the path must belong
to P {i}.
Proposition 3. The labels of nodes joining P can only increase in successive iterations.
Proof. We again use induction on the size of P .
Base: When |P | = 1, the only node in P is s, which has a label 0. Since all costs are nonnegative,
all other nodes will have labels 0.
Inductive step: Assume for |P | = k and prove for |P | = k + 1.
Assume by contradiction that node i with d(i) = min{d(j) : j T }, was added to P , but in a later
iteration node j is added to P having a label d(j) < d(i). This contradicts the Theorem 1.1 since
if the graph had a zero-cost arc (j, i), then the shortest distance from s to i would be d(j) (< d(i)
which was the label of node i when added to the permanent set).

Complexity Analysis
There are two major operations in Dijkstras algorithm :
Find minimum, which has O(n2 ) complexity; and
Update labels, which has O(m) complexity.
Therefore, the complexity of Dijkstras algorithm is = O(n2 + m).
There are several implementations that improve upon this running time.
One improvement uses Binary Heaps: whenever a label is updated, use binary search to insert
that label properly in the sorted array. This requires O(log n). Therefore, the complexity of
finding the minimum label in temporary set is O(m log n), and complexity of the algorithm is
O(m + m log n) = O(m log n).

Another improvement is Radix Heap which has complexity O(m+n log C) where C = max(i,j)A cij .
But this is not a strongly polynomial complexity.
Currently, the best strongly polynomial implementation of Dijkstras algorithm uses Fibonacci
Heaps and has complexity O(m + n log n). Since Fibonacci heaps are hard to program, this implementation is not used in practice.
It is important to stress that Dijkstras algorithm does not work correctly in the presence of
negative edge weights. In this algorithm once a node is included in the permanent set it will not be
checked later again, but because of the presence of negative edge that is not correct. The problem
is that the distance label of a node in the permanent set might be reduced after its inclusion in the
permanent set (when considering negative cost arcs).
See Figure 1 for an example such that Dijkstras algorithm does not work in presence of negative
edge weight. Using the algorithm, we get d(3) = 3. But the actual value of d(3) is 2.


1 XX

X3

XXX
z
B
3
B


4B
B
-2
BBN

2



Figure 1: Network for which Dijkstras algorithm fails

You might also like