双枢轴快速排序中的INSERTION_SORT_THRESHOLD

时间:2019-06-27 13:21:02

标签: java arrays sorting quicksort insertion-sort

为什么在所有n> = 2的nlogn小于n ^ 2的情况下,Java在Arrays类中使用了47的INS​​ERTION_SORT_THRESHOLD?它与硬件恒定开销有关系吗?

private static void sort(int[] a, int left, int right, boolean leftmost) {
    int length = right - left + 1;

    // Use insertion sort on tiny arrays
    if (length < INSERTION_SORT_THRESHOLD) {
        if (leftmost) {
            /*
             * Traditional (without sentinel) insertion sort,
             * optimized for server VM, is used in case of
             * the leftmost part.
             */
            for (int i = left, j = i; i < right; j = ++i) { 

0 个答案:

没有答案