-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Added implementation for MSD radix sort algorithm based on binary representation #4441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
sorts/msd_radix_sort.py
Outdated
>>> _msd_radix_sort([10, 4, 12], 2) | ||
[4, 12, 10] | ||
""" | ||
if bit_position == 0 or len(list_of_ints) == 1 or len(list_of_ints) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling len()
two times here is inefficient. Let's imagine 1kk list :)
len(list_of_ints) in (0, 1)
sorts/msd_radix_sort.py
Outdated
zeros = list() | ||
ones = list() | ||
# Split numbers based on bit at bit_position from the right | ||
for index, number in enumerate(list_of_ints): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index never used so go without enumerate
return [] | ||
|
||
if min(list_of_ints) < 0: | ||
raise ValueError("All numbers must be positive") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add test for this assertion.
Hey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
…resentation (TheAlgorithms#4441) * Added MSD radix sort algorithm * Fixed typos * Added doctests * Added link to wikipedia * Added doctest and improved code
Describe your change:
Added implementation for the MSD radix sort algorithm. The sorting is based on the binary
representation of the numbers.
Checklist:
Fixes: #{$ISSUE_NO}
.