In this lecture, restricted cases for shortest-paths algorithms are covered including:

  • Only non-negative edge weights allowed: Dijkstra’s algorithm
  • Input graph is acyclic (DAG): single-source s-p algorithm for DAGs

Dijkstra’s shortest-paths algorithm

We make the critical assumption that all edge weights are non-negative. For convenience, also assume all nodes are reachable from .

Dijkstra's Shortest-paths Algorithm

def dijkstra(G, w, s):
	(V, E) = G
	
	relax_init(G, s) # from relaxation technique
	S = set() # nodes for which we know d[v] = delta(s,v)
	Q = V # other nodes in a Priority Queue with keys d[.]
	
	while not empty(Q):
		u = extract_min(Q) # find u with minimum d[.] value in Q
		S = S | {u}
		
		for node v in Adj[u]:
			relax_edge(u, v, w)

Correctness of Dijkstra’s algorithm

We look at an intermediate state of the computation (at the end of one iteration).

Set grows by one node per iteration. (1st iter: , last iter: ) All edges from nodes in , and only these edges, have been relax’ed. All nodes in or at the end of edges from :

  • have finite values (by induction)
  • have parents, forming a tree (no negative cycle and property 8)

For all other nodes, , and not in the parent tree.

At the end of the computation:

Set is . For each , is finite and . The parent subgraph is a tree (rooted at ) which includes all nodes.

We haven't shown yet that the computed tree is a shortest-paths tree and the values are the shortest-path weights.

The Crucial Property (invariant of Dijkstra’s)

The crucial property (invariant of computation of Dijkstra’s algorithm) is that: at the end of each iteration (on the main loop) of Dijkstra’s algorithm, for each node : .

This property can be shown by induction on the number of iterations. Base Case Property holds on first iteration

Inductive Case Assume the invariant holds at the end of some iteration (not last one):

Let denote the node selected in the next (current) iteration.

Show that the invariant holds at the end of the current iteration (after has been added to set ). That is, show .

In other words, we have to show that at the beginning of the current iteration, is the shortest-path weight from to .

We have (relaxation technique).

Let’s show that .

  • Take any (simple) path from to and show its weight .
  • Let be the first node on path which is outside , and let be the predecessor of on (so ).
  • Let be the initial part of the path ending at node , and let be the part of the path from node to the final node . The inequalities in above follow from: the inductive assumption, RELAX() done, the rule for selecting , and the non-negative weights of edges, respectively.

Hence, no path from to has smaller weight than , so .

Running time of Dijkstra’s algorithm

Using an unordered list

Using an ordered list

lgt

Priority Queue using a heap

Shortest-paths algorithms for DAGs

Incomplete

1 item under this folder.