-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dijkstra O(N^2) #8
Comments
Great catch. I will update the code, which I believe I only need to heapify once after the for-loop. Thanks @yanpozka |
Original fix and tests are at: And the fix for this repository here: Thanks again @yanpozka |
Good job @gyuho !! You're welcome! Always it's a pleasure to find people who cares about algorithm. |
Thanks! |
Hey man, good job, I just detected that your Go implementation of Dijkstra algorithms is O(N^2)
https://github.com/gyuho/learn/tree/master/doc/go_graph_shortest_path#dijkstra-algorithm
So the issue is that you have a O(N logN) solution in your description but in your Golang implementation if you include heap.Init(...) inside the loop:
for minHeap.Len() != 0
you'll have a N^2 time because the method heap.Init() has a time of O(N) so that call is inside of a O(N) loop.
Happy coding !!
The text was updated successfully, but these errors were encountered: