‹ 上一题 下一题 ›

g5-04362. GESP-5级-2025-06-单选-第14题 未做

1000 ms 256 MB 测试点 ? GESPGESP-52025-06单选客观题5级·排序排序算法

关于下述 C++ 代码的快速排序算法,说法错误的是( )。

int randomPartition(std::vector<int>& arr, int low, int high) {
    int random = low + rand() % (high - low + 1);
    std::swap(arr[random], arr[high]);

    int pivot = arr[high];
    int i = low - 1;

    for (int j = low; j < high; j++) {
        if (arr[j] <= pivot) {
            i++;
            std::swap(arr[i], arr[j]);
        }
    }
    std::swap(arr[i + 1], arr[high]);
    return i + 1;
}

void quickSort(std::vector<int>& arr, int low, int high) {
    if (low < high) {
        int pi = randomPartition(arr, low, high);

        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}
  • A. 在 randomPartition 函数中,变量 i 的作用是记录大于基准值的元素的边界
  • B. randomPartition 函数随机选择基准值,可以避免输入数据特定模式导致的最坏情况下时间复杂度
  • C. 快速排序平均时间复杂度是
  • D. 快速排序是稳定排序算法
未选择
输入
输出

            
答案