I am solving UVa site problems, I have a problem that I must sort the integers as fast as possible.
I have tried the bubble sort, but it is inefficient. I have tried the quick sort, which uses recursion, but it results a StackOverflowException, since the input is very large (almost 20 millions).
The problem's time limit is only 5 seconds. Does anyone have any ideas on how to implement this more efficiently?
O(log N)stack. Constraints would have to be very tight indeed to prevent this handling 20M elements. You do this by call-recursing on the smaller partition, and looping to do the larger partition, so your function is only singly-recursive. See stackoverflow.com/q/6709055/13005 for why it's this way around. Only a multiply-recursive quicksort need riskO(n)stack depth.std::sortin C++,Arrays.sortin Java orqsortin C.