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
More efficient implementation for 4.3.23 #148
Comments
The algorithm you suggested works and is more efficient, but it is basically Kruskal's algorithm, and not Vyssotsky's, so I'm not sure if it is the idea of the exercise. |
I agree, my version really does look like the Kruskal's algorithm. Thank you for the improvement, it seems reasonable! |
By the way, since you are checking this chapter I invite you to take a look at exercise 4.3.44, |
I've seen your solution, and I didn't have any ideas about improving its time complexity. Do you think that there exists a more optimal approach when using doubly-linked-lists? |
I'm not sure. The final time complexity seems to be O(E lg V), which is the expected time complexity in the exercise. |
Yes, it's strange that the exercise explicitly mentions doubly-linked circular lists, but it's unclear, how to utilize this property. Have you tried to directly contact Robert Sedgewick (rs@cs.princeton.edu) and ask him for help? |
I haven't tried yet but I will try and if I find something I will update the exercise. |
Thanks! Maybe it's a good idea to also write to Kevin Wayne (the second author of the book, wayne@cs.princeton.edu). Please, comment something in this issue if you get any answer. |
I guess, there's a more efficient implementation for the Vyssotsky’s algorithm (4.3.23). We could sort all edges of the original graph by weight and start adding them in that order to the MST. If we find a cycle, we just skip the current edge, as it is the longest so far. Here's the implementation:
The time complexity should be
O(E*(logE + logV))
(firstlogE
is for sorting all edges, the secondlogV
(or even the inverse Ackermann function) is for union-find), which is much better thanO(E^2)
.There's a note in the book:
I think, there may be an even more efficient implementation, but I don't have any more ideas for now.
The text was updated successfully, but these errors were encountered: