Back to questionsDSA Visualizers: 388 Coding Questions Counting Sort visualizer Learn Counting Sort with a step-by-step Sorting visualizer, JavaScript source code and a worked example. Practice elementary and divide and conquer.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 17 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input [
4,
2,
2,
8,
3,
3,
1
] Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = (a,s)=>{
2 let c=Array(Math.max(...a)+1 ).fill(0 ),out=[];
3 a.forEach((x,i)=>{
4 c[x]++;
5 s("Count key",{
6 Array:a,Counts:c
7 },[i])
8 });
9 c.forEach((n,x)=>{
10 while (n--)out.push(x);
11 s("Emit values",{
12 Counts:c,Sorted:out
13 })
14 });
15 return out
16 };
Execution canvas Active ChangedSTEP 1 Count key Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Sorting · Elementary and divide and conquer
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input [
4,
2,
2,
8,
3,
3,
1
] Execution steps Count key Emit values Computed output [
1,
2,
2,
3,
3,
4,
8
] JavaScript reference implementation const solve = (a,s)=>{
let c=Array(Math.max(...a)+1).fill(0),out=[];
a.forEach((x,i)=>{
c[x]++;
s("Count key",{
Array:a,Counts:c
},[i])
});
c.forEach((n,x)=>{
while(n--)out.push(x);
s("Emit values",{
Counts:c,Sorted:out
})
});
return out
};Continue learning Practice related DSA questions in the same topic.