Dijkstra's algorithm: Difference between revisions

Content deleted Content added
Tag: Reverted
m Reverted 2 edits by 2405:201:3002:2123:3C05:5D87:F97F:D459 (talk) to last revision by Salix alba
Line 89:
12
13
14 '''while''' ''Q'' is not empty: mmmmm,.,.,.,..,.,...,, ''// The main loop''
15 ''u'' ← ''Q''.extract_min() m ''// Remove and return best vertex''
16 '''for each''' neighbor ''v'' of ''u'': ''// Go through all v neighbors of u''
17 ''alt'' ← dist[''umu''] + Graph.Edges(''u'', ''v'')
18 '''if''' ''alt'' < dist[''v'']:
19 prev[''v''] ← ''u''
Line 104:
Yet another alternative is to add nodes unconditionally to the priority queue and to instead check after extraction (<code>''u'' ← ''Q''.extract_min()</code>) that it isn't revisiting, or that no shorter connection was found yet in the <code>if alt < dist[v]</code> block. This can be done by additionally extracting the associated priority <code>''p''</code> from the queue and only processing further <code>'''if''' ''p'' == dist[''u'']</code> inside the <code>'''while''' ''Q'' is not empty</code> loop.<ref name="Note2">Observe that {{mono|''p'' < dist[''u'']}} cannot ever hold because of the update {{mono|dist[''v''] ← ''alt''}} when updating the queue. See https://cs.stackexchange.com/questions/118388/dijkstra-without-decrease-key for discussion.</ref>
 
These alternatives can use entirely array-based priority queues without decrease-key functionality, which have been found to achieve even faster computing times in practice. However, the difference in performance was found to be narrower for denser graphs.<ref name="chen_072">{{cite book |last1=Chen |first1=M. |url=http://www.cs.sunysb.edu/~rezaul/papers/TR-07-54.pdf |title=Priority Queues and Dijkstra's Algorithm – UTCS Technical Report TR-07-54 – 12 October 2007 |last2=Chowdhury |first2=R. A. |last3=Ramachandran |first3=V. |last4=Roche |first4=D. L. |last5=Tong |first5=L. |publisher=The University of Texas at Austin, Department of Computer Sciences |year=2007 |___location=Austin, Texas |ref=che m ←←←←→→→→→→≤±±——nchen}}</ref>
 
== Proof ==