For any queries you can reach us at / WhatsApp us: +919158876092

Radix Sort in Data Structures - Infovistar

Radix Sort

Radix sort is a generalization of a bucket sort. Radix sort is a linear sorting algorithm that is used to sort integers.

Radix sort performs digit sorting from the least significant to the most significant digit.

To sort decimal numbers, where the radix or base is 10, we need 10 buckets. These buckets are numbered from 0 - 9.

A radix sort works similar to sorting students' names alphabetically.

Range Passes
0 to 99 2 Passes
0 to 999 3 Passes
0 to 9999 4 Passes
0 to 99999 5 Passes
  • For the first pass, numbers are sorted by least significant digit. Numbers with same least significant digit are stored in the same bucket.
  • In the second pass, numbers are sorted by the second least significant digit.
  • The numbers in buckets are merged at the end of every pass to produce a common list.
  • Number of passes depends on the range of numbers being sorted.

Time Complexity

Case Time Complexity
Best Case Ω (n + k)
Average Case θ (n k)
Worst Case O (n k)
  • Best Case Ω (n + k):It occurs when there is no sorting needed, i.e. the array is already sorted.
  • Average Case θ (n k): The array elements are in a jumbled order that is not properly ascending and descending.
  • Worst Case O (n k): This occurs when the array elements need to be sorted in reverse order.

Space Complexity

Space Complexity O(n + k)
Stable Yes
  • The space complexity of radix sorting is O (n + k).

Radix Sort