Content deleted Content added
m Signing comment by 188.192.84.92 - "→A doubt: " |
|||
Line 125:
The program I made based on the pseudocode didn't work until I made this change. Can anyone confirm that this is indeed the case (and not just some other bug in my program) and if so, correct the article? --[[User:Smallhacker|Smallhacker]] ([[User talk:Smallhacker|talk]]) 15:38, 3 March 2011 (UTC)
==== proposed answer ====
for i from 1 to size(vertices) - 1▼
▲ for i from 1 to size(vertices) - 1
is correct.
in other other words: you intentionally leave one vertex out.
reason:
let a shortest path from '''s''' to an arbitrary vertex '''v''' contain ''k'' edges.
that means, the path ''p'' from s to v can be described as follows: ''p'' = ('''s''' = v<sub>0</sub>, v<sub>1</sub>, ..., v<sub>k-1</sub>, v<sub>k</sub> = '''v''').
in the worst case the shortest path visits all vertices of the graph. these are size(vertices). but the path between '''s''' and '''v''' only contains size(vertices) - 1 edges.
the algorithm tries to relax all edges for every edge on the shortest path - followingly, only size(vertices) - 1 relax-iterations have to be computed.
|