Single-Source Shortest Paths

Example

Graph

Adjacency Matrix

0123456
00130000
11015000
23100100
30500200
40012040
50000402
60000020

Dijkstra's Algorithm

Require non-negative weights

Time Complexity: O((|E|+|V|)log|V|) (use heap or priority queue) or O(|E|+|V|log|V|) (use Fibonacci heap min-priority queue)

Tests