24-4 Gabow's scaling algorithm for single-source shortest paths

A scaling algorithm solves a problem by initially considering only the highestorder bit of each relevant input value (such as an edge weight). It then refines the initial solution by looking at the two highest-order bits. It progressively looks at more and more high-order bits, refining the solution each time, until it has examined all bits and computed the correct solution.

In this problem, we examine an algorithm for computing the shortest paths from a single source by scaling edge weights. We are given a directed graph G=(V,E)G = (V, E) with nonnegative integer edge weights ww. Let W=max(u,v)E{w(u,v)}W = \max_{(u, v) \in E} \{w(u, v)\}. Our goal is to develop an algorithm that runs in O(ElgW)O(E\lg W) time. We assume that all vertices are reachable from the source.

The algorithm uncovers the bits in the binary representation of the edge weights one at a time, from the most significant bit to the least significant bit. Specifically, let k=lg(W+1)k = \lceil \lg(W + 1) \rceil be the number of bits in the binary representation of WW, and for i=1,2,,ki = 1, 2, \ldots, k, let wi(u,v)=w(u,v)/2kiw_i(u, v) = \lfloor w(u, v) / 2^{k - i} \rfloor. That is, wi(u,v)w_i(u, v) is the "scaled-down" version of w(u,v)w(u, v) given by the ii most significant bits of w(u,v)w(u, v). (Thus, wk(u,v)=w(u,v)w_k(u, v) = w(u, v) for all (u,v)E(u, v) \in E.) For example, if k=5k = 5 and w(u,v)=25w(u, v) = 25, which has the binary representation 11001\langle 11001 \rangle, then w3(u,v)=110=6w_3(u, v) = \langle 110 \rangle = 6. As another example with k=5k = 5, if w(u,v)=00100=4w(u, v) = \langle 00100 \rangle = 4, then w3(u,v)=001=1w_3(u, v) = \langle 001 \rangle = 1. Let us define δi(u,v)\delta_i(u, v) as the shortest-path weight from vertex uu to vertex vv using weight function wiw_i. Thus, δk(u,v)=δ(u,v)\delta_k(u, v) = \delta(u, v) for all u,vVu, v \in V. For a given source vertex ss, the scaling algorithm first computes the shortest-path weights δ1(s,v)\delta_1(s, v) for all vVv \in V, then computes δ2(s,v)\delta_2(s, v) for all vVv \in V, and so on, until it computes δk(s,v)\delta_k(s, v) for all vVv \in V. We assume throughout that EV1|E| \ge |V| - 1, and we shall see that computing δi\delta_i from δi1\delta_{i - 1} takes O(E)O(E) time, so that the entire algorithm takes O(kE)=O(ElgW)O(kE) = O(E\lg W) time.

a. Suppose that for all vertices vVv \in V, we have δ(s,v)E\delta(s, v) \le |E|. Show that we can compute δ(s,v)\delta(s, v) for all vVv \in V in O(E)O(E) time.

b. Show that we can compute δ1(s,v)\delta_1(s, v) for all vVv \in V in O(E)O(E) time.

Let us now focus on computing δi\delta_i from δi1\delta_{i - 1}.

c. Prove that for i=2,3,,ki = 2, 3, \ldots, k, we have either wi(u,v)=2wi1(u,v)w_i(u, v) = 2w_{i - 1}(u, v) or wi(u,v)=2wi1(u,v)+1w_i(u, v) = 2w_{i - 1}(u, v) + 1. Then, prove that

2δi1(s,v)δi(s,v)2δi1(s,v)+V12\delta_{i - 1}(s, v) \le \delta_i(s, v) \le 2\delta_{i - 1}(s, v) + |V| - 1

for all vVv \in V.

d. Define for i=2,3,,ki = 2, 3, \ldots, k and all (u,v)E(u, v) \in E,

w^i=wi(u,v)+2δi1(s,u)2δi1(s,v).\hat w_i = w_i(u, v) + 2\delta_{i - 1}(s, u) - 2\delta_{i - 1}(s, v).

Prove that for i=2,3,,ki = 2, 3, \ldots, k and all u,vVu, v \in V, the "reweighted" value w^i(u,v)\hat w_i(u, v) of edge (u,v)(u, v) is a nonnegative integer.

e. Now, define δ^i(s,v)\hat\delta_i(s, v) as the shortest-path weight from ss to vv using the weight function w^i\hat w_i. Prove that for i=2,3,,ki = 2, 3, \ldots, k and all vVv \in V,

δi(s,v)=δ^i(s,v)+2δi1(s,v)\delta_i(s, v) = \hat\delta_i(s, v) + 2\delta_{i - 1}(s, v)

and that δ^i(s,v)E\hat\delta_i(s, v) \le |E|.

f. Show how to compute δi(s,v)\delta_i(s, v) from δi1(s,v)\delta_{i - 1}(s, v) for all vVv \in V in O(E)O(E) time, and conclude that we can compute δ(s,v)\delta(s, v) for all vVv \in V in O(ElgW)O(E\lg W) time.

a. We can do this in O(E)O(E) by the algorithm described in exercise 24.3-8 since our "priority queue" takes on only integer values and is bounded in size by EE.

b. We can do this in O(E)O(E) by the algorithm described in exercise 24.3-8 since ww takes values in {0,1}\{0, 1\} and V=O(E)V = O(E).

c. If the iith digit, read from left to right, of w(u,v)w(u, v) is 00, then wi(u,v)=2wi1(u,v)w_i(u, v) = 2w_{i − 1}(u, v). If it is a 11, then wi(u,v)=2wi1(u,v)+1w_i(u, v) = 2w_{i − 1}(u, v) + 1. Now let s=v0,v1,,vn=vs = v_0, v_1, \dots, v_n = v be a shortest path from ss to vv under wiw_i. Note that any shortest path under wiw_i is necessarily also a shortest path under wi1w_{i − 1}. Then we have

δi(s,v)=m=1nwi(vm1,vm)m=1n[2wi1(u,v)+1]m=1nwi1(u,v)+n2δi1(s,v)+V1. \begin{aligned} \delta_i(s, v) & = \sum_{m = 1}^n w_i(v_{m − 1}, v_m) \\ & \le \sum_{m = 1}^n [2w_{i − 1}(u, v) + 1] \\ & \le \sum_{m = 1}^n w_{i − 1}(u, v) + n \\ & \le 2\delta_{i − 1}(s, v) + |V| − 1. \end{aligned}

On the other hand, we also have

δi(s,v)=m=1nwi(vm1,vm)m=1n2wi1(vm1,vm)2δi1(s,v). \begin{aligned} \delta_i(s, v) & = \sum_{m = 1}^n w_i(v_{m - 1}, v_m) \\ & \ge \sum_{m = 1}^n 2w_{i - 1}(v_{m - 1}, v_m) \\ & \ge 2\delta_{i - 1}(s, v). \end{aligned}

d. Note that every quantity in the definition of w^i\hat w_i is an integer, so w^i\hat w_i is clearly an integer. Since wi(u,v)2wi1(u,v)w_i(u, v) \ge 2w_{i - 1}(u, v), it will suffice to show that wi1(u,v)+δi1(s,u)δi1(s,v)w_{i - 1}(u, v) + \delta_{i - 1}(s, u) \ge \delta_{i - 1}(s, v) to prove nonnegativity. This follows immediately from the triangle inequality.

e. First note that s=v0,v1,,vn=vs = v_0, v_1, \dots, v_n = v is a shortest path from ss to vv with respect to $\hatw$ if and only if it is a shortest path with respect to ww. Then we have

δ^i(s,v)=m=1nwi(vm1,vm)+2δi1(s,vm1)2δi1(s,vm)=m=1nwi(vm1,vm)2δi1(s,vn)=δi(s,v)2δi1(s,v). \begin{aligned} \hat\delta_i(s, v) & = \sum_{m = 1}^n w_i(v_{m - 1}, v_m) + 2\delta_{i - 1}(s, v_{m - 1}) − 2\delta_{i - 1}(s, v_m) \\ & = \sum_{m = 1}^n w_i(v_{m - 1}, v_m) − 2\delta_{i - 1}(s, v_n) \\ & = \delta_i(s, v) − 2\delta_{i - 1}(s, v). \end{aligned}

f. By part (a) we can compute δ^i(s,v)\hat\delta_i(s, v) for all vVv \in V in O(E)O(E) time. If we have already computed δi1\delta_i - 1 then we can compute δi\delta_i in O(E)O(E) time. Since we can compute δ1\delta_1 in O(E)O(E) by part b, we can compute δi\delta_i from scratch in O(iE)O(iE) time. Thus, we can compute δ=δk\delta = \delta_k in O(Ek)=O(ElgW)O(Ek) = O(E\lg W) time.