Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AK: Guarantee a maximum stack depth for dual_pivot_quick_sort
When the two chosen pivots happen to be the smallest and largest elements of the array, three partitions will be created, two of size 0 and one of size n-2. If this happens on each recursive call to dual_pivot_quick_sort, the stack depth will reach approximately n/2. To avoid the stack from deepening, iteration can be used for the largest of the three partitions. This ensures the stack depth will only increase for partitions of size n/2 or smaller, which results in a maximum stack depth of log(n).
- Loading branch information