Originally posted by: yukichigai
I still say Radix Sort will be satisfactory for this problem. Just... slightly modified. I doubt it would be faster than whatever the guys JayHu mentioned have come up with, but it's what came to mind and I want to tell y'all about it. Allow me to explain.
Radix Sort sorts based on each character/digit of a sequence. So in an array of 5 3-digit numbers it examines the hundreds place first, then the tens, then the ones, lumping them together in their individual sub-groups each time. For a task like this, just using a raw Radix Sort would be fast, but there's a certain logic that allows some optimizations to be made to the Radix Sort algorithm. All you're looking for here is the 10 highest numbers. Let me try to explain this....
Say you have an array of 7 digit numbers of size n.
Okay, first digit. The Radix sort gets them all organized by the 10^6 magnitude. (Or whatever the hell the term is. i.e. numbers starting with 9 grouped together, then 8, so on and so forth)
Second digit. The Radix sort starts sorting, but once it completes sorting in each grouping made by the previous digit -- e.g. finishes sorting everything starting with a 9 -- it checks to see if it's sorted at least 10 entries. If it has, it stops and moves on to the next digit, discarding all other numbers. If it has sorted EXACTLY 10 entries it stops completely and gives you that grouping of numbers. (And maybe sorts it real quick, if you really want)
Third digit. Exact same thing as above.
And so on and so forth.
Does that make any sense?
Like I said, I don't think it'll be better than what the geniuses came up with, but I had to mention it.