Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------------------------------
- Function dijkstra(Graph, source, destination)
- Q = vertex set
- s = source vertex
- g = goal vertex
- weight = 0
- best_vertex = s
- for each vertex v in Graph
- distance to v = infinity
- add v to Q
- previous_vertex = undefined (previous vertex in optimal path from source)
- distance to source = 0
- while Q not empty
- best_neighbour = vertex in Q with minimum weight from s
- remove best_neighbour from Q
- for each neighbour v of best_neighbour
- potential_path = distance to best_neighbour + edge(best_neighbour, v)
- if potential_path < distance to v
- distance to v = potential_path
- previous_vertex = best_neighbour
- return
- ---------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement