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 digit_number 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 is_done as a loop variable because the value of is_done is related to digit_number.
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
digit_number
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
is_done
as a loop variable because the value ofis_done
is related todigit_number
.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: