N
N
NoMoneyException2016-09-24 00:09:18
Java
NoMoneyException, 2016-09-24 00:09:18

How to get rid of StackOverFlow when sorting recursively?

How can I sort an array of, say, 10^6 elements using recursive quick sort? As I understand it, the thread's memory runs out, and it throws an exception. How do they deal with this in Java, or do they just use a different sort?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2016-09-24
@eugene_leshchinskiy

To do this, use the "springboard" pattern. There is a good implementation example on StackOverflow (alas, the text is in English):
stackoverflow.com/a/32909860/1293168

S
Stanislav Makarov, 2016-09-24
@Nipheris

It is not necessary to use the system call stack as the "stack". You can use a loop instead of recursion, and use a stack in your programming language library instead of the system call stack. Instead of a recursive call, you will have to put a tuple of values ​​- sorting parameters - on the stack and extract them from there at the next processing step.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question