Skip to main content

Counting Sort

A non-comparison sort that counts occurrences of each value and reconstructs the array in order.

Interactive Visualization

Loading visualization…

Usage

import { countingSort } from 'athro';

const arr = [4, 2, 2, 8, 3, 3, 1];
countingSort(arr);
Note

Works best when the range of input values is small relative to array length.

Time Complexity

CaseTime ComplexityDescription
BestO(n + k)k is the value range
AverageO(n + k)Linear scan of counts
WorstO(n + k)Same regardless of input order