0
0
DSA Javascriptprogramming~10 mins

Counting Sort Algorithm in DSA Javascript - Interactive Practice

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

Complete the code to initialize the count array with zeros.

DSA Javascript
const count = new Array(max + 1).fill([1]);
Drag options to blanks, or click blank then click option'
A0
B1
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 causes incorrect counts.
Using null or undefined causes errors when incrementing.
2fill in blank
medium

Complete the code to count the frequency of each element in the input array.

DSA Javascript
for (let i = 0; i < arr.length; i++) {
  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 -- decreases the count incorrectly.
Using = overwrites the count instead of incrementing.
3fill in blank
hard

Fix the error in the code to compute the cumulative count correctly.

DSA Javascript
for (let i = 1; i <= max; i++) {
  count[i] = count[i] [1] count[i - 1];
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction causes wrong cumulative counts.
Using multiplication or division is incorrect here.
4fill in blank
hard

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

DSA Javascript
for (let i = arr.length - 1; i >= 0; i--) {
  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 causes index errors.
Incrementing count instead of decrementing breaks stability.
5fill in blank
hard

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

DSA Javascript
for (let i = 0; i < arr.length; ) {
  arr[[1]] = output[[2]];
  [3];
}
Drag options to blanks, or click blank then click option'
Ai
Ci++
D++i
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indices causes wrong copying.
Forgetting to increment i causes infinite loop.