测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A22007. 下述C++代码实现了快速排序算法,最坏情况的时间复杂度是( )。int partition(vector<int>& arr, int low, int high) { int i = low, j = high; int pivot = arr[low]; //以首元素为基准 while (i < j) { while (i < j && arr[j] >= pivot) j--; while…

单选题 困难

题目描述

下述C++代码实现了快速排序算法,最坏情况的时间复杂度是(    )。

int partition(vector<int>& arr, int low, int high) {
    int i = low, j = high;
    int pivot = arr[low];       //以首元素为基准
    while (i < j) {
        while (i < j && arr[j] >= pivot) j--;
        while (i < j && arr[i] <= pivot) i++;
        if (i < j) swap(arr[i], arr[j]);
    }
    swap(arr[i], arr[low]);
    return i;
}

void quickSort(vector<int>& arr, int low, int high) {
    if (low >= high) return;
    int p = partition(arr, low, high);
    quickSort(arr, low, p - 1);
    quickSort(arr, p + 1, high);
}

选项(单选)

上一题 下一题