Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Algorithm Weird(G, s)
- 1 for v in V:
- 2 val[v] = ∞
- 3 val[s]= 0
- 4 A = {} # A is a set
- 5 while A != V:
- 6 select vertex x not in A with minimum val[x]
- 7 A = A ∪ {x}
- 8 for each vertex y adjacent to x:
- 9 if val[x] + w(x, y) < val[y]:
- 10 val[y] = val[x] + w(x, y)
- On applying this to the graph at http://imgur.com/a4CCo6O, I get the following result :-
- val = {0, 1, 5, 8, 13}
- Answer found on IRC #algorithms : This is Dijkstra's algorithm.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement