Skip to content
Advertisement

Non-recursive Quicksort

How do i make the bottom function non-recursive, ive tried but by creating new functions which is not the point in this problem. The first function is given and the inplace_quicksort_non_recursive is created by me.

JavaScript

What do i need to create so the bottom function becomes non-recursive

Advertisement

Answer

The question is using a variation of Hoare partition scheme (but with issues). Example with classic Hoare partition scheme. Note Hoare splits partition into elements <= pivot and elements >= pivot; the pivot and elements == pivot can end up anywhere, so Hoare only splits partition into 2 parts (the pivot is not put into place and cannot be excluded from later partition steps).

JavaScript

In response to comment, a simple example in C++.

JavaScript

The original version of quicksort limited stack space to 2*ceil(log2(size)) by pushing indexes of larger partition onto stack, and looping on smaller partition. Hoare used the term “nest” instead of stack in his original paper.

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