I would like to know if there is any api available for Java which is just like heapq in Python.
Actually i wanted to do this in java.http://stackoverflow.com/questions/1034846/finding-nth-item-of-unsorted-list-without-sorting-the-list/1036240#1036240
Emil
2010-09-17 10:27:50
@Emil: Okay, so what's stopping you? It's probably easiest to specify a reversing comparator, and then just use the iterator from the head of the queue.
Jon Skeet
2010-09-17 10:34:56
@Jon:Is this the best way to find the k'th smallest element?I found selection algorithms with complexity O(n) as the answer to the question.But couldn't find any implementation in Java.
Emil
2010-09-17 10:44:32
@Emil: No, I doubt that it's the best way to find the kth smallest element, as it's basically sorting the whole thing. Just take the selection algorithms you've found and port them to Java - it shouldn't be too hard.
Jon Skeet
2010-09-17 10:50:14
A:
Yes +1 to Jon, you know we have to :).
By the way, here is the link for elaboration.
Adeel Ansari
2010-09-17 10:29:17