Search code examples
algorithmdata-structuresgraphgraph-algorithmdijkstra

Do indexed priority queues actually speed up dijkstra?


The "lazy" dijkstra's shortest path algorithm has an asymptotic time complexity of O(Elog(V)), which uses a regular priority queue instead of an indexed heap. This means that there will be duplicate nodes that the algorithm will have to skip over, but handle regardless. A solution to this is to use the indexed priority queue, but I am confused on whether it is actually faster, both in real life and with big O, than the lazy version, since the lazy version still skips the duplicate nodes very early in the algorithm. With some research I have also found that indexed dijkstra has a better space complexity of O(V) than the lazy implementation's O(E), I am not aware whether this improves performance or not.


Solution

  • It does not reduce theoretical asymptotic time complexity, and it remains O(ElogV).

    Regardless if you actually insert or replace an element in the existing heap, it still is going to take O(log|H|) time (where |H| is the size of the heap).

    In "lazy" version, |H| is in O(|E|), and in non "lazy", it is in O(|V|), so time complexity is O(|E|log|E|) in lazy version, and O(|E|log|V|) in non lazy version.

    But since |E| itself is in O(|V|^2), and since log(|V|^2) =2log(|V|), it means O(|E|log|V|) = O(|E|log|E|), and asymptotic theoretical complexity remains the same.