Advertisement
Guest User

Untitled

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