add_edge(G, u, v, z)
get_edge_value(G, u, v): value
set_edge_value(G, u, v, z)
get_vertex_value(G, u): value
set_vertex_value(G, u, z)
: define o valor associado ao vértice $u$ do grafo $G$ como sendo $z$ for i from 1 to |V|
for j from 1 to |V|
dist[i][j] = get_edge_cost(G, i, j)
for k from 1 to |V|
for i from 1 to |V|
for j from 1 to |V|
if dist[i][j] > dist[i][k] + dist[k][j]
dist[i][j] ← dist[i][k] + dist[k][j]
end if
Complexidade de tempo: $O( | V | ^3)$ |
function Dijkstra(Graph, source):
for each vertex v in Graph.Vertices:
dist[v] ← INFINITY
prev[v] ← UNDEFINED
add v to Q
dist[source] ← 0
while Q is not empty:
u ← vertex in Q with min dist[u]
remove u from Q
for each neighbor v of u still in Q:
alt ← dist[u] + Graph.Edges(u, v)
if alt < dist[v]:
dist[v] ← alt
prev[v] ← u
return dist[], prev[]