fix: handle empty input in jump_search - #14807
Merged
cclauss merged 3 commits intoSep 6, 2026
Merged
Conversation
mindaugl
approved these changes
Jun 15, 2026
jordandunmire97-ai
approved these changes
Jun 28, 2026
priya-sundaram-dev
approved these changes
Sep 6, 2026
priya-sundaram-dev
left a comment
Contributor
There was a problem hiding this comment.
Correct edge-case fix: jump_search([], item) previously computed block_size = int(math.sqrt(0)) = 0 and could loop/misbehave; returning -1 for an empty array is the right contract and matches the "not found" return. Doctest added, CI green. LGTM ✅
Note for the maintainers: #15101 is an identical fix to the same function — this one (#14807) came first, so I'd suggest merging this and closing #15101 as a duplicate.
This was referenced Sep 6, 2026
cclauss
enabled auto-merge (squash)
September 6, 2026 06:19
cclauss
approved these changes
Sep 6, 2026
This was referenced Sep 6, 2026
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:
Fixed
jump_search([], item)so it returns-1instead of raisingIndexError.Why
The function documents
-1as the result when the item is not found. An empty collection is a valid not-found case and should not attempt to index into the sequence.How tested
/opt/homebrew/opt/python@3.14/bin/python3.14 -m doctest -v searches/jump_search.pyfailed withIndexErrorbefore the fix/opt/homebrew/opt/python@3.14/bin/python3.14 -m doctest -v searches/jump_search.py/tmp/thealgorithms-py314-pytest/bin/python -m pytest --doctest-modules searches/jump_search.py -qgit diff --checkChecklist: