24-6 Bitonic shortest paths
A sequence is bitonic if it monotonically increases and then monotonically decreases, or if by a circular shift it monotonically increases and then monotonically decreases. For example the sequences , , and are bitonic, but is not bitonic. (See Problem 15-3 for the bitonic euclidean traveling-salesman problem.)
Suppose that we are given a directed graph with weight function , where all edge weights are unique, and we wish to find single-source shortest paths from a source vertex . We are given one additional piece of information: for each vertex , the weights of the edges along any shortest path from to form a bitonic sequence.
Give the most efficient algorithm you can to solve this problem, and analyze its running time.
We'll use the Bellman-Ford algorithm, but with a careful choice of the order in which we relax the edges in order to perform a smaller number of operations. In any bitonic path there can be at most two distinct increasing sequences of edge weights, and similarly at most two distinct decreasing sequences of edge weights. Thus, by the path-relaxation property, if we relax the edges in order of increasing weight then decreasing weight twice (for a total of four times relaxing every edge) the we are guaranteed that will equal for all . Sorting the edges takes . We relax every edge times, taking . Thus the total runtime is , which is asymptotically faster than the usual runtime of Bellman-Ford.