Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does introsort shift from quicksort to heapsort?

Introsort begins with quicksort and switches to heapsort when the recursion depth exceeds a level based on the number of elements being sorted. What is that number? Is there a specific range or a limiting value?

like image 648
sachin irukula Avatar asked Jun 24 '12 06:06

sachin irukula


1 Answers

The point at which the Introsort algorithm switches from Quicksort to Heapsort is determined by depth_limit:

depth_limit = 2 · ⎣log2(l)⎦

Where l is the length of the sequence that is to be sorted, so l‍=‍n for the whole sequence. With each recursive call depth_limit is decremented by one. When depth_limit reaches 0, it switches from Quicksort to Heapsort.

like image 151
Gumbo Avatar answered Oct 03 '22 12:10

Gumbo