Counting Sort Visualizer
Learn Counting Sort by watching frequency counts and output placement evolve with interactive controls and step-by-step explanations.
Comma-separated numbers, up to 20 values.
Live operation
current
Count array
Stable output
Comparisons
0
Moves / writes
0
Confirmed sorted
0 / 8
Algorithm notes
What to watch for
Counting Sort avoids value-to-value comparisons. It is efficient when the range of integer keys is reasonably small, trading extra count-array memory for linear-style passes.
Concept guide
Review the mental model, tradeoffs, and practical use cases after you experiment.
Counting Sort Complete Info Card
Counting Sort is a non-comparison based sorting algorithm that works by counting occurrences of each unique element, then calculating positions to reconstruct the sorted array. Ideal for integer data with limited range.
Algorithm Characteristics
Time Complexity (Best)
Linear time performance
Time Complexity (Average)
Consistent performance
Time Complexity (Worst)
Depends on input range
Space Complexity
Auxiliary count array needed
Stable
Maintains relative order
In-Place
Requires extra memory
Sorting Process Steps
Find maximum element in array
Create count array of size k
Store element counts in count array
Convert count array to cumulative sums
Build output array using count positions
Key Features & Considerations
| Feature | Advantages | Limitations |
|---|---|---|
| Non-Comparison Based | Beats O(n log n) limit | Only works with integers |
| Stable Sort | Preserves original order | Requires careful implementation |
| Range Dependent | Excellent for small ranges | Inefficient for large k |
| Integer Keys | Perfect for counting data | Not for floating points |
| Linear Time | Predictable performance | Memory intensive for large k |
Optimal Use Cases
- •Sorting integers with limited range
- •When stability is required
- •As subroutine for Radix Sort
When to Avoid
- •Sorting non-integer data
- •Large value ranges (k >> n)
- •Memory-constrained environments