10BC0 Fix complexity of Dijkstra's algorithm · cp-algorithms/cp-algorithms@0804f41 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0804f41

Browse files
authored
Fix complexity of Dijkstra's algorithm
Error mentioned here: e9d37eb#r28480357
1 parent d332467 commit 0804f41

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/graph/dijkstra_sparse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We recall in the derivation of the complexity of Dijkstra's algorithm we used tw
99
the time of finding the unmarked vertex with the smallest distance $d[v]$, and the time of the relaxation, i.e. the time of changing the values $d[\text{to}]$.
1010

1111
In the simplest implementation these operations require $O(n)$ and $O(1)$ time.
12-
Therefore, since we perform the first operation $O(n)$ times, and the second one $O(m)$ times, we obtained the complexity $O(n^2 m)$.
12+
Therefore, since we perform the first operation $O(n)$ times, and the second one $O(m)$ times, we obtained the complexity $O(n^2 + m)$.
1313

1414
It is clear, that this complexity is optimal for a dense graph, i.e. when $m \approx n^2$.
1515
However in sparse graphs, when $m$ is much smaller than the maximal number of edges $n^2$, the complexity gets less optimal because of the first term.

0 commit comments

Comments
 (0)
0