Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. -------------------------------------------------------------------
  2. Function dijkstra(Graph, source, destination)
  3.  
  4. Q = vertex set
  5.  
  6. for each vertex v in Graph
  7. distance to v = infinity
  8. add v to Q
  9. previous_vertex = undefined (previous vertex in optimal path from source)
  10. distance to source = 0
  11.  
  12. while Q not empty
  13. best_neighbour = vertex in Q with minimum distance from s
  14. remove best_neighbour from Q
  15. for each neighbour v of best_neighbour
  16. potential_path = distance to best_neighbour + edge(best_neighbour, v)
  17. if potential_path < distance to v
  18. distance to v = potential_path
  19. previous_vertex = best_neighbour
  20. return
  21. ---------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement