0
0
DSA C++programming~10 mins

Counting 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 declare the count array with the correct size.

DSA C++
int count[[1] + 1] = {0};
Drag options to blanks, or click blank then click option'
Asum
Bmin_val
Cn
Dmax_val
Attempts:
3 left
💡 Hint
Common Mistakes
Using the size of the input array instead of the maximum value.
Using minimum value for size.
2fill in blank
medium

Complete the code to increment the count of the current element.

DSA C++
count[arr[i]][1];
Drag options to blanks, or click blank then click option'
A++
B--
C+=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using decrement operator instead of increment.
Assigning instead of incrementing.
3fill in blank
hard

Fix the error in updating the count array to hold cumulative counts.

DSA C++
for (int i = 1; i <= [1]; i++) {
    count[i] = count[i] [2] count[i - 1];
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
Dmax_val
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using multiplication or division which is incorrect.
4fill in blank
hard

Fill both blanks to place elements in the output array in correct order.

DSA C++
output[count[arr[i]] [1]] = arr[i];
count[arr[i]] [2];
Drag options to blanks, or click blank then click option'
A- 1
B+ 1
C--
D++
Attempts:
3 left
💡 Hint
Common Mistakes
Not subtracting 1 causing off-by-one errors.
Incrementing count instead of decrementing.
5fill in blank
hard

Fill all three blanks to copy the sorted output back to the original array.

DSA C++
for (int i = 0; i < [1]; i++) {
    arr[i] = [2][[3]];
}
Drag options to blanks, or click blank then click option'
An
Boutput
Ci
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong array names.
Using wrong index variables.