Open In App

Time and Space complexity of Radix Sort Algorithm

Last Updated : 09 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The Radix Sort Algorithm has a time complexity of O(n*d), where n is the number of elements in the input array and d is the number of digits in the largest number. The space complexity of Radix Sort is O(n + k), where n is the number of elements in the input array and k is the range of the input. This algorithm is efficient for sorting integers, especially when the range of values is not significantly larger than the number of elements to be sorted.

Complexity Radix Sort Algorithm
Time Complexity O(n*d)
Space Complexity O(n + k)

Let’s explore the detailed time and space complexity of the Radix Sort Algorithm:

Time Complexity of Radix Sort Algorithm:

Best Case Time Complexity: O(n*d)

  • The best-case time complexity of Radix Sort is O(n*d), where n is the number of elements in the input array and d is the number of digits in the largest number.
  • In the best case, Radix Sort performs similarly to the average case, as it processes all digits of all elements.

Average Case Time Complexity: O(n*d)

  • The average-case time complexity of Radix Sort is O(n*d).
  • Radix Sort processes each digit of each element in the input array, making its time complexity linear with respect to the number of elements and digits.

Worst Case Time Complexity: O(n*d)

  • The worst-case time complexity of Radix Sort is O(n*d).
  • In the worst case, when all elements have the same digits or the digits are in reverse order, Radix Sort still needs to process each digit of each element.

Auxiliary Space of Radix Sort Algorithm:

  • The space complexity of Radix Sort is O(n + k), where n is the number of elements in the input array and k is the range of the input.
  • Radix Sort requires additional space for the buckets used during sorting and for storing the sorted output.
  • The space complexity can be higher when dealing with a large range of input values.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads