Search code examples
arraysalgorithmradix-sort

Sorting arrays with Radixsort


I am currently trying to understand Radixsort and therefor i have a short question.

What I think is very bad to sort with Radixsort, is the array below:

"9999...9, 9999...9, 9999...9"

Because Radixsort will compare every single number of the first, second and third number in the array. So it would be better to use another sortingalgorithm for this array. I am right or are there other arrays which are very disadvantageous to sort with Radixsort?

Best regards


Solution

  • Time cost of a radix sort is O(nm) where n is the number of elements and m is the complexity of the elements. You are right, there are instances where it is not faster. With long integer strings, m can exceed logn which nlogn would be the time cost of a merge sort for example.