Are these two relations the same?

58 Views Asked by At

Suppose we want to find the shortest path with at most $\ell$ edges in a positive weighted directed graph $G=(V,E)$ with weight $w(u,w)$ on each edge.

According to Jeff Erickson's algorithms textbook, a dynamic programming approach for the above problem is to use this recurrence relation:

$$\begin{equation} d_{u,v}^\ell=\begin{cases} w(u,v), & \text{if $\ell=1$}.\\ \min_{x\in V}(d_{u,x}^{\lceil{\frac{\ell}{2}}\rceil}+d_{x,v}^{\lfloor{\frac{\ell}{2}}\rfloor}), & \text{otherwise}. \end{cases} \end{equation} $$

But my question is if we write the above recurrence as

$$\begin{equation} d_{u,v}^\ell=\begin{cases} w(u,v), & \text{if $\ell=1$}.\\ \min_{x\in V}(d_{u,v}^{\ell-1},d_{u,x}^{\lceil{\frac{\ell}{2}}\rceil}+d_{x,v}^{\lfloor{\frac{\ell}{2}}\rfloor}), & \text{otherwise}. \end{cases} \end{equation} $$

can we conclude that two relations give us an optimal solution?

1

There are 1 best solutions below

7
On

I think the first recurrence should be $d_{u,v}^l = \min_{x\in V}d_{u,x}^{\lceil\frac{l}{2} \rceil} +d_{v,x}^{\lfloor \frac{l}{2} \rfloor}$ if $l > 1$

$d_{u,v}^l = \min_{x\in V}d_{u,x}^{l-1} + w(x, v)$ is also a correct recurrence, and is the one used in the Bellman Ford algorithm.

The benefit of the first recurrence is that for an all-pairs shortest path, the $l$ is divided by $2$ instead of being decreased by $1$ at each step, which results in only $\log_2(n)$ steps performed instead of $n$.