3 ms·
Well, this is nice. However, I'm a bit surprised that you did a straight Quicksort. What I mean is that Quicksort has O(n^2) worst-case time complexity. But th
by ggchappell 18y ago
Well, this is nice. However, I'm a bit surprised that you did a straight Quicksort.
What I mean is that Quicksort has O(n^2) worst-case time complexity. But the Introsort variant (Musser 1997) has O(n log n) worst case, is no slower than Quicksort in the average case, and requires no significant additional space.
Introsort is a modification of Quicksort: it keeps track of the recursion depth (counting tail calls as recursive calls). And if the depth exceeds 2 log_2 n, then it switches to Heap Sort for the current sublist.
- ais 18y agoThanks for the introsort suggestion... I'll be sure to investigate. There is a general purpose quicksort implementation included in the package... but the numerical sorting routines are primarily radix sort based and will not fall victim to the recursion problem.