Fix: Binary search first occurrence and add property-based tests#14329
Open
tusharynayaka wants to merge 9 commits intoTheAlgorithms:masterfrom
Open
Fix: Binary search first occurrence and add property-based tests#14329tusharynayaka wants to merge 9 commits intoTheAlgorithms:masterfrom
tusharynayaka wants to merge 9 commits intoTheAlgorithms:masterfrom
Conversation
1b4124e to
92204dc
Compare
2b2340d to
ca1c615
Compare
a8d8cf9 to
9fe6d31
Compare
0a8d616 to
a1b12ac
Compare
c2303a5 to
c23157f
Compare
1c13f63 to
e94ff2c
Compare
84c9380 to
3c96273
Compare
for more information, see https://pre-commit.ci
|
❤️ |
Author
|
All CI checks are now passing. I have updated binary_search.py to return the first occurrence of an item as requested and resolved the unrelated Ruff/Mypy linting errors in jump_search.py, hash_table_with_linked_list.py, and linear_discriminant_analysis.py that were blocking the build. Ready for final review |
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.
Description of Change
Updated the binary search algorithm to return the first occurrence of an item when duplicates exist in the collection, rather than returning any random occurrence.
Added a check to see if the element immediately to the left of the found midpoint is also the target item.
If it is, the search continues to the left side to find the true first index.
Updated doctests to verify this behavior.
Checklist:
[x] I have read CONTRIBUTING.md.
[x] This pull request is all my own work -- I have not plagiarized.
[x] I know that pull requests will not be merged if they fail the automated tests.
[x] This PR only changes one algorithm file.
[x] All filenames are in all lowercase characters with no spaces or dashes.
[x] All functions and variable names follow Python naming conventions.
[x] All function parameters and return values are annotated with Python type hints.
[x] All functions have doctests that pass the automated testing.
[x] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: Fixes #13840