Content deleted Content added
TSP is NP-complete, which is a more precise notion than NP-hard |
→Description of the algorithm: mention relaxation |
||
Line 23:
the cost of the shortest path from ''s'' to ''v'' or infinity, if no such path exists.
The
to a path from ''s'' to ''v'' by adding edge (''u'',''v'') at the end. This path will have length ''d''[''u'']+''w''(''u'',''v''). If this is less than
''d''[''v''], we can replace current value of ''d''[''v''] with the new value.
Edge relaxation is applied until all values ''d''[''v''] represent the cost of the shortest path from ''s'' to ''v''. The algorithm is organized so that each edge (''u'',''v'') is relaxed only once, when ''d''[''u''] has reached its final value.
The algorithm maintains two sets of vertices ''S'' and ''Q''. Set ''S'' contains all vertices for which we know that the value ''d''[''v''] is already the cost of the shortest path and set ''Q'' contains all other vertices.
Set ''S'' starts empty, and in each step one vertex is moved from ''Q'' to ''S''. This vertex chosen as the vertex with lowest value of ''d''[''u''].
When a vertex ''u'' is moved to ''S'', the algorithm
outgoing edge (''u'',''v'')
==Pseudocode==
|