Fix: Binary search first occurrence and add property-based tests#14329
Fix: Binary search first occurrence and add property-based tests#14329tusharynayaka wants to merge 11 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
|
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 |
|
Hi @tusharynayaka. Do you know if this project is still active? Will your code be reviewed soon? |
@OliCheesman |
tusharynayaka
left a comment
There was a problem hiding this comment.
Applied the feedback from the previous thread. Tests are passing and I'm ready for a final sign-off to get this merged.
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