0
0
DSA C++programming~10 mins

Radix 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 get the maximum value in the array for Radix Sort.

DSA C++
int getMax(int arr[], int n) {
    int max = arr[0];
    for (int i = 1; i < n; i++) {
        if (arr[i] [1] max) {
            max = arr[i];
        }
    }
    return max;
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes the max to never update correctly.
2fill in blank
medium

Complete the code to count the occurrences of digits for the current place value in Counting Sort used by Radix Sort.

DSA C++
void countSort(int arr[], int n, int exp) {
    int output[n];
    int count[10] = {0};

    for (int i = 0; i < n; i++) {
        count[(arr[i] / [1]) % 10]++;
    }
    // rest of the code...
}
Drag options to blanks, or click blank then click option'
Aexp
Barr[i]
Cn
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 instead of exp will always count the units digit only.
3fill in blank
hard

Fix the error in the loop that builds the output array in Counting Sort for Radix Sort.

DSA C++
for (int i = n - 1; i >= 0; i--) {
    output[count[(arr[i] / exp) % 10] [1]] = arr[i];
    count[(arr[i] / exp) % 10]--;
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' will cause index overflow and incorrect placement.
4fill in blank
hard

Fill both blanks to copy the output array back to the original array after Counting Sort step.

DSA C++
for (int i = 0; i [1] n; i++) {
    arr[i] = [2][i];
}
Drag options to blanks, or click blank then click option'
A<
B<=
Coutput
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes out-of-bounds error.
Copying from count instead of output causes wrong data.
5fill in blank
hard

Fill all three blanks to complete the main Radix Sort loop that calls Counting Sort for each digit place.

DSA C++
void radixSort(int arr[], int n) {
    int m = getMax(arr, n);

    for (int exp = 1; exp [1] m; exp = exp [2] 10) {
        countSort(arr, n, [3]);
    }
}
Drag options to blanks, or click blank then click option'
A>
B*
Cexp
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<=' causes the loop to never run.
Passing m instead of exp to countSort causes wrong sorting.