0
0
DSA C++programming~10 mins

Quick Sort Algorithm in DSA C++ - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to swap two elements in the array.

DSA C++
void swap(int& a, int& b) {
    int temp = a;
    a = [1];
    b = temp;
}
Drag options to blanks, or click blank then click option'
A0
Ba
Ctemp
Db
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'a' to itself instead of 'b'.
Using 'temp' incorrectly.
2fill in blank
medium

Complete the code to choose the pivot element for partitioning.

DSA C++
int partition(int arr[], int low, int high) {
    int pivot = arr[[1]];
    int i = low - 1;
    for (int j = low; j < high; j++) {
        if (arr[j] < pivot) {
            i++;
            swap(arr[i], arr[j]);
        }
    }
    swap(arr[i + 1], arr[high]);
    return i + 1;
}
Drag options to blanks, or click blank then click option'
Ahigh
Blow
Clow + 1
Dhigh - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the wrong index for the pivot.
Using an index outside the array bounds.
3fill in blank
hard

Fix the error in the recursive quickSort call to sort the left partition.

DSA C++
void quickSort(int arr[], int low, int high) {
    if (low < high) {
        int pi = partition(arr, low, high);
        quickSort(arr, low, [1]);
        quickSort(arr, pi + 1, high);
    }
}
Drag options to blanks, or click blank then click option'
Api
Bpi - 1
Clow
Dhigh
Attempts:
3 left
💡 Hint
Common Mistakes
Including the pivot index in the left partition.
Using the wrong boundary for recursion.
4fill in blank
hard

Fill both blanks to complete the partition function's loop condition and swap call.

DSA C++
int partition(int arr[], int low, int high) {
    int pivot = arr[high];
    int i = low - 1;
    for (int j = low; j [1] high; j++) {
        if (arr[j] [2] pivot) {
            i++;
            swap(arr[i], arr[j]);
        }
    }
    swap(arr[i + 1], arr[high]);
    return i + 1;
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' in the loop condition causing out-of-bound errors.
Using '>' instead of '<=' in the if condition.
5fill in blank
hard

Fill all three blanks to complete the quickSort function with correct recursive calls and base condition.

DSA C++
void quickSort(int arr[], int low, int high) {
    if (low [1] high) {
        int pi = partition(arr, low, high);
        quickSort(arr, low, [2]);
        quickSort(arr, [3], high);
    }
}
Drag options to blanks, or click blank then click option'
A<
Bpi - 1
Cpi + 1
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators in the base condition.
Including the pivot index in recursive calls.