mirror of
https://github.com/mfocko/blog.git
synced 2024-12-22 06:01:26 +01:00
algorithms(bf-to-astar): mention time complexity in BF
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
b048c6dc4f
commit
a1f871ffb8
1 changed files with 21 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue