Update merge_insertion_sort.py#5833
Merged
poyea merged 4 commits intoTheAlgorithms:masterfrom Dec 16, 2021
Merged
Conversation
Fixes TheAlgorithms#5774 merge_insertion_sort Co-Authored-By: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>
MaximSmolskiy
requested changes
Nov 18, 2021
Fixes TheAlgorithms#5774 merge_insertion_sort Co-Authored-By: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>
Contributor
Author
|
Thank you for the hint! We found out why our solution didn't work properly and we have updated it: Now we check if the length of the input is an odd number, so that the if only triggers if that is the case. Furthermore we have tested this on all permutations from range(0,10). |
MaximSmolskiy
approved these changes
Nov 19, 2021
Member
MaximSmolskiy
left a comment
There was a problem hiding this comment.
Yes, now it passes these tests
Fixes TheAlgorithms#5774 added permutation range from 0 to 4 Co-Authored-By: AilisOsswald <44617437+AilisOsswald@users.noreply.github.com>
Rohanrbharadwaj
approved these changes
Nov 24, 2021
Contributor
|
Looks good, don't mind adding a |
Contributor
Author
|
Could any one have a look please? We would appreciate if we could have a feedback :) |
poyea
approved these changes
Dec 16, 2021
Member
|
Let's use |
poyea
approved these changes
Dec 16, 2021
14 tasks
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.
Fixes #5774
merge_insertion_sort
Co-Authored-By: AilisOsswald 44617437+AilisOsswald@users.noreply.github.com
Describe your change:
We fixed the Issue of Merge-insertion-Sort not sorting correctly.
We have seen that there is already a PR but we would like to present our fix since it is a little bit different: reidstrieker@2ab90df
We have left all Code as it was before, except line 163
original:
if result[i] == collection[-i]:
corrected:
if result[i] == collection[-1]:
because as the flag name states we want to check if the current item in result is the last item of our input list. (which would be collection[-1] not [-i]
We think that both solutions should work, but the solution with checking (as described above) should perform a tiny bit better.
Normally we do this, since we know everything left to the current value is smaller than the value we will have to sort in:
result = result[: i + 1] + binary_search_insertion(result[i + 1 :], pivot)
If we find the last_odd_item in our result list, we know the same thing like above and we know that there is one additional value, which is already sorted - the last_odd_item. And with that knowlegde we can make the list we have to search through smaller and the list we don't have to look at larger by one each:
result = result[: i + 1 +1] + binary_search_insertion(result[i + 1 :], pivot)
Keeping this flag in the code should make it a bit quicker, since in some cases the list to be searched through is one element smaller.
Our next step would be writing more tests as suggested in this issue #5774. Should this be done in the same issue or in a new one?
Checklist:
Fixes: #{$ISSUE_NO}.