Added implementation for MSD radix sort algorithm based on binary representation#4441
Merged
l3str4nge merged 5 commits intoTheAlgorithms:masterfrom May 20, 2021
Txbias:master
Merged
Added implementation for MSD radix sort algorithm based on binary representation#4441l3str4nge merged 5 commits intoTheAlgorithms:masterfrom Txbias:master
l3str4nge merged 5 commits intoTheAlgorithms:masterfrom
Txbias:master
Conversation
l3str4nge
requested changes
May 20, 2021
| >>> _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: |
Member
There was a problem hiding this comment.
Calling len() two times here is inefficient. Let's imagine 1kk list :)
len(list_of_ints) in (0, 1)
| zeros = list() | ||
| ones = list() | ||
| # Split numbers based on bit at bit_position from the right | ||
| for index, number in enumerate(list_of_ints): |
Member
There was a problem hiding this comment.
index never used so go without enumerate
| return [] | ||
|
|
||
| if min(list_of_ints) < 0: | ||
| raise ValueError("All numbers must be positive") |
Member
There was a problem hiding this comment.
Please add test for this assertion.
Contributor
Author
|
Hey, |
shermanhui
pushed a commit
to shermanhui/Python
that referenced
this pull request
Oct 22, 2021
…resentation (TheAlgorithms#4441) * Added MSD radix sort algorithm * Fixed typos * Added doctests * Added link to wikipedia * Added doctest and improved code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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}.