This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Algorithm to find the kth largest element in unsorted list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Algorithm to find the kth largest element in unsorted list" Watch "Algorithm to find the kth largest element in unsorted list" New topic
Author

Algorithm to find the kth largest element in unsorted list

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Here is what I could write.



It has a bug. It is producing incorrect output for k=2. For k=1,3,4,5,6 , it is working fine.


~ Mansukh
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Mansukhdeep Thind wrote:Here is what I could write.

Rather than prolong this too much, here's my solution. See if you follow it:it probably needs a check or two to make it bulletproof; but hopefully you get the general idea.

Winston

PS: So I lied; 30 lines, not 20.

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I nailed it Winston. Here is my code:



I shall mark this as resolved now. Thanks all you guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Algorithm to find the kth largest element in unsorted list
 
Similar Threads
Core Java Real time based questions
How to compare the elements of the array and remove the smallest item?!
A time complexity question
compiling help
Sorting An Array of Objects