CPKit
v1.6.1

Counting Sort

SortingMedium

Frequencies counts to achieve O(N) non-comparison sorts.

Alt+Shift+C

Configuration Panel

Frequencies Accumulation Visualizer

5
0
2
1
8
2
2
3
3
4
5
5
1
6
4
7
Step: 1 / 1

Time Complexity

O(N + K) where K is the range of values (Max - Min)

Space Complexity

O(K) auxiliary counts list
Conceptual Overview

Counting Sort is a non-comparison integer sorting algorithm that works by counting the number of occurrences of each unique element value, then calculating indices directly.

Algorithm Idea

Initialize a frequency count array of size Max + 1 with 0. Scan the array to increment occurrences. Scan the count array to reconstruct sorted numbers.

Stable Sorting

Stable (when implemented with index prefix sums back sweeps)

In-place Memory

Out-of-place (requires O(MaxElement) frequency storage)

Source: CP-Algorithms search & sorting reference