Skip to content
Advertisement

How to fix StackOverflow error while using Quicksort for big arrays?

I’m doing a benchmark for different sorting and I’m getting a StackOverflowError using Quicksort for an array of size 100,000.

JavaScript

I will also need to use Quicksort to sort an array of size 1,000,000 so I will get this problem again.

I read about increasing the stack size but didn’t figure out how to do it properly.

Advertisement

Answer

To limit stack space to O(log(n)), recurse on smaller partition, loop back on larger partition. Worst case time complexity remains O(n^2)).

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement