What is the time complexity of the radix sort algorithm?

Algorithm Design Questions Medium



49 Short 51 Medium 39 Long Answer Questions Question Index

What is the time complexity of the radix sort algorithm?

The time complexity of the radix sort algorithm is O(d * (n + k)), where d is the number of digits in the maximum number, n is the number of elements to be sorted, and k is the range of possible values for each digit (usually 10 for decimal numbers).

Radix sort is a non-comparative sorting algorithm that sorts elements by their individual digits. It works by sorting the elements based on each digit from the least significant to the most significant. The algorithm performs counting sort for each digit, which has a time complexity of O(n + k), where n is the number of elements and k is the range of possible values for that digit.

Since radix sort performs counting sort for each digit, the time complexity is multiplied by the number of digits, which is d. Therefore, the overall time complexity of radix sort is O(d * (n + k)).