algorithms(bf-to-astar): mention time complexity in BF

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-01-01 21:32:04 +01:00
parent b048c6dc4f
commit a1f871ffb8
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -387,6 +387,27 @@ possibly look it up, if necessary.
Also the correctness of the BF relies on the conclusion we've made when fixing
the infinite-loop on our naïve BF solution.
## Time complexity
Let's have a short look at the time complexities of the presented algorithms:
1. naïve approach: given that there are no negative loops, we are bound by the
worst-case ordering of the relaxations which results in
$$
\mathcal{O}(\vert V \vert \cdot \vert E \vert)
$$
2. our naïve approach with the fixed count of iterations instead of the
`do-while` loop results in the same worst-case time complexity:
$$
\mathcal{O}(\vert V \vert \cdot \vert E \vert)
$$
3. and finally the well-known Bellman-Ford's algorithm time complexity:
$$
\mathcal{O}(\vert V \vert \cdot \vert E \vert)
$$
## Small refactor
Since we are literally copy-pasting the body of the loops just for the sake of