Skip to content

fix: handle empty input in jump search - #3259

Open
devam007 wants to merge 1 commit into
TheAlgorithms:masterfrom
devam007:codex/jump-search-empty-input
Open

devam007 wants to merge 1 commit into
TheAlgorithms:masterfrom
devam007:codex/jump-search-empty-input

Conversation

@devam007

Copy link
Copy Markdown

Description of Change

Return -1 for n <= 0 before jump search reads the array. Previously, a zero-sized
step could read arr[-1] and even return a match for a logically empty range.
Add assertions for empty input, null with zero length, singletons, duplicates,
end-position matches and absent targets. Retain the existing example.

Validation

GCC 15.2 / C++17: 41,311 focused reference comparisons pass against
std::binary_search with seeded sorted inputs and boundary targets. A safe backing-
array reproduction returns an incorrect match on the base and -1 with the fix.
Warning-enabled compilation with libstdc++ assertions, the CMake/Ninja target,
the source assertions and git diff --check pass. Remote CI, clang-format and
clang-tidy were not run locally.

  • Read contribution guidelines and kept the change to one algorithm file
  • Added regression assertions and verified the existing example
  • Reviewed the patch for unrelated changes

Related prior work: #3169 included empty-input handling in a broader vector/API rewrite and was closed unmerged after inactivity. This patch keeps the existing array API and limits the change to the boundary guard and regression assertions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant