Test cases for interpolation_search - #10690
Open
RaymondDashWu wants to merge 19 commits into
Open
RaymondDashWu wants to merge 19 commits into
RaymondDashWu wants to merge 19 commits into
Conversation
cclauss
reviewed
Oct 19, 2023
… interpolation_search_tests
for more information, see https://pre-commit.ci
… interpolation_search_tests
…ndDashWu/Python into interpolation_search_tests
for more information, see https://pre-commit.ci
cclauss
reviewed
Oct 20, 2023
| def interpolation_search(sorted_collection, item): | ||
| def interpolation_search(sorted_collection: list[int], item: int) -> int | None: | ||
| """Pure implementation of interpolation search algorithm in Python | ||
| Be careful collection must be ascending sorted, otherwise result will be |
Member
There was a problem hiding this comment.
Please test for this condition. Give it an unsorted input and lets see if it fails or not.
Contributor
Author
There was a problem hiding this comment.
An unsorted input doesn't work with this implementation unfortunately. For example >>> interpolation_search([5, 0, 1], 2) == None will return True despite 2 not being in the array. I wasn't sure how to handle this as there is a helper function called __assert_sorted. I considered adding that code at the beginning of each function but that changes the time complexity of the functions from logn to nlogn. If something is done to sanitize the input I assume it should be done in a separate PR.
cclauss
reviewed
Oct 20, 2023
… interpolation_search_tests
…ndDashWu/Python into interpolation_search_tests
for more information, see https://pre-commit.ci
…ndDashWu/Python into interpolation_search_tests
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:
Contributes to #9943
Checklist: