Time Complexity
insert
- Each node is added to priority queue once
relax/decreaseKey
times - Each edge is relaxed once
Implementation of queue | insert | deleteMin | decreaseKey | Time complexity |
---|---|---|---|---|
Array | ||||
AVL Tree | ||||
d-way Heap | ||||
Fibonacci Heap |
Proof of Correctness
Proof by induction
- Every finished vertex has correct estimate.
- Basis step: The start vertex is finished and has a correct estimate.
- Inductive step:
- Remove vertex from priority queue
- Relax edges
- Changes priority if there is a vertex in priority queue with less priority
- Add vertex to set of finished vertices
- Estimate of vertex is final
Invariants
- Vertex is finished when dequeued.
- Estimate is never changed
- When destination is reached, we can stop the algorithm
Limitations
- Fails with negative weights.
- Graphs cannot be reweighted.