qsort switching to insertsort

Arne Dag Fidjestøl adf at idi.ntnu.no
Sat Nov 26 17:14:13 UTC 2016


> On 26 Nov 2016, at 15:35, Mehmet Erol Sanliturk <m.e.sanliturk at gmail.com> wrote:
> 
> In quick sort , it is necessary to check worst case and switch to another
> sort method if it is detected .
> When this is not done , end result is stack overflow , etc . , but not
> success .
> Therefore , it is not possible to eliminate an alternative sort method .

I you sort the smaller partition recursively first, and then sort the larger partition either by tail recursion or iteration, you will only consume O(log n) of stack, so stack overflow needn’t be an issue, regardless of the input.

-adf


More information about the freebsd-hackers mailing list