You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if the test case for radix_sort.py is [104, 203, 308, 401], the result would be [401, 203, 104, 308]
It's wrong!
The reason is that if the tmp is always 0 in one loop, it will exit the loop. In other words, If the same digit of all numbers is 0, then the result may be wrong. The similar example like: Input: [2018, 33017, 24016] Output: [24016, 33017, 2018]
Wrong again!!
Suggestion
Do not use maxLength as a loop variable because the value of maxLength is related to tmp.
I think that by finding the maximum value of the array and assigning it to max_digit, using another variable digit with an initial value of 1 as the loop variable, each loop digit is multiplied by 10, and exit the loops when the digit greater than max_digit, which can guarantee the correct number of loops.
And the complexity will be O(nk + n) . n is the size of input list and k is the digit length of the number.
The text was updated successfully, but these errors were encountered:
Description
if the test case for
radix_sort.py
is[104, 203, 308, 401]
, the result would be[401, 203, 104, 308]
It's wrong!
The reason is that if the
tmp
is always0
in one loop, it will exit the loop. In other words, If the same digit of all numbers is 0, then the result may be wrong. The similar example like:Input:
[2018, 33017, 24016]
Output:
[24016, 33017, 2018]
Wrong again!!
Suggestion
Do not use
maxLength
as a loop variable because the value ofmaxLength
is related totmp
.I think that by finding the maximum value of the array and assigning it to
max_digit
, using another variabledigit
with an initial value of 1 as the loop variable, each loopdigit
is multiplied by 10, and exit the loops when thedigit
greater thanmax_digit
, which can guarantee the correct number of loops.And the complexity will be O(nk + n) . n is the size of input list and k is the digit length of the number.
The text was updated successfully, but these errors were encountered: