# Johnson's vs Floyd-Warshall for dense graphs

I often read that Floyd-Warshall is a good fit for dense graphs and Johnson's for sparse ones. While it's easy to see why Johnson outperforms Floyd-Warshall on sparse graphs, I'm noticing that Johnson's with Fibonacci Heaps does no worse than Floyd-Warshall in terms of asymptotic runtime.

More specifically, from what I see, for dense graphs we have:

• Floyd-Warshall runs in $$O(V^3)$$
• Johnson's algorithm with a Fibonacci Heap runs in $$O(VE + V^2\text{lg}V$$) which for a dense graph would also be $$O(V^3)$$

If so, what are the exact benefits of Floyd-Warshall over Johnson's? Is it runtime differences in practice? Space complexity? Something else?

To put it more bluntly (at the risk of oversimplifying this matter) could one say e.g. "Always use Johnson's over Floyd-Warshall"?.

• The five lines of code for Floyd-Warshall fit on the back of a beer coaster. On the other hand I need two hours and a blackboard to start explaining Fibonacci heaps. Commented Apr 11, 2020 at 17:54