Explain more the Dijkstra implementation [closes #48]

This commit is contained in:
Antti H S Laaksonen 2017-04-23 13:24:13 +03:00
parent a4d7df8d1e
commit c775c02881
1 changed files with 5 additions and 2 deletions

View File

@ -580,12 +580,15 @@ while (!q.empty()) {
Note that the priority queue contains \emph{negative} Note that the priority queue contains \emph{negative}
distances to nodes. distances to nodes.
The reason for this is that the C++ priority queue finds the \emph{maximum} The reason for this is that the C++ priority queue finds maximum
element by default while we would like to find \emph{minimum} elements. elements by default while we want to find minimum elements.
By using negative distances, By using negative distances,
we can directly use the default version of the C++ priority queue\footnote{Of we can directly use the default version of the C++ priority queue\footnote{Of
course, we could also declare the priority queue as in Chapter 4.5 course, we could also declare the priority queue as in Chapter 4.5
and use positive distances, but the implementation would be a bit longer.}. and use positive distances, but the implementation would be a bit longer.}.
Also note that there may be several instances of the same
node in the priority queue; however, only the instance with the
minimum distance will be processed.
The time complexity of the above implementation is The time complexity of the above implementation is
$O(n+m \log m)$ because the algorithm goes through $O(n+m \log m)$ because the algorithm goes through