Counting Sort Visualizer

0 elements
50%
Placements: 0
Range: N/A
Status: Idle

Counting Sort Explained

Counting Sort is a non-comparative algorithm that counts occurrences of each value and places them in sorted order, excelling when the range (k) is close to the number of elements (n).

Algorithm Characteristics

  • Time ComplexityO(n + k)
  • Space ComplexityO(n + k)
  • StabilityYes
  • Best forSmall k

Key Properties

  • Non-comparative: uses counting instead of comparisons

  • Stable: preserves order of equal elements

  • Linear time when range (k) is close to n

  • Requires extra space proportional to n + k

Counting Sort outperforms O(n log n) sorts when k is small