Divide and Conquer
Get to know divide and conquer techniques used to solve the all-pairs shortest paths problem
We'll cover the following
Improving Bellman-Ford algorithm
Now let’s look at how we can make a more significant improvement, suggested by Michael Fischer and Albert Meyer in 1971. Bellman’s recurrence breaks the shortest path into a slightly shorter path and a single edge by considering all possible predecessors of the target vertex. Instead, let’s break the shortest paths into two shorter shortest paths at the middle vertex. This idea gives us a different recurrence for the same function . Here we need to stop at the base case instead of because a path with at most one edge has no “middle” vertex. To simplify the recurrence slightly, let’s define for every vertex .
As stated, this recurrence only works when is a power of , since otherwise, we might try to find the shortest path with (at most) a fractional number of edges! But that’s not really a problem; is the true shortest path distance from to for all ; in particular, we can use .
Once again, a dynamic programming solution is straightforward. Even before we write down the algorithm, we can tell the running time is —we need to consider possible values of , , and but only possible values of .
Fischer and Meyer’s algorithm
In the following pseudocode for Fischer and Meyer’s algorithm, the array entry stores the value of .
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy