Skip to content

fix(searches): empty jump_search input; validate cyclic_sort - #15147

Open
felipeofdev-ai wants to merge 3 commits into
TheAlgorithms:masterfrom
felipeofdev-ai:fix/jump-search-empty-list-and-cyclic-sort-validation
Open

fix(searches): empty jump_search input; validate cyclic_sort#15147
felipeofdev-ai wants to merge 3 commits into
TheAlgorithms:masterfrom
felipeofdev-ai:fix/jump-search-empty-list-and-cyclic-sort-validation

Conversation

@felipeofdev-ai

@felipeofdev-ai felipeofdev-ai commented Sep 1, 2026

Copy link
Copy Markdown

Summary

Test plan

  • python -m doctest searches/jump_search.py sorts/cyclic_sort.py
  • uvx ruff check sorts/cyclic_sort.py searches/jump_search.py
  • Manual check: jump_search([], 5) returns -1
  • Manual check: cyclic_sort([1, 1, 2]) raises ValueError

fix(sorts): validate cyclic_sort input to prevent infinite loops

Fixes TheAlgorithms#15085

Fixes TheAlgorithms#14898
@felipeofdev-ai
felipeofdev-ai force-pushed the fix/jump-search-empty-list-and-cyclic-sort-validation branch from c041e4b to b80d47d Compare September 1, 2026 14:37
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label Sep 1, 2026
@felipeofdev-ai
felipeofdev-ai force-pushed the fix/jump-search-empty-list-and-cyclic-sort-validation branch from 10cfe92 to 2fb19fb Compare September 1, 2026 14:45
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Sep 1, 2026
@prashantpiyush1111

Copy link
Copy Markdown

Reviewed the current diff and both changed files. The jump_search fix is correctly guarded before the square-root/block-size calculation, so an empty sequence now returns -1 instead of reaching an invalid index access. The added doctest covers that regression.

For cyclic_sort, validating the input before entering the cyclic loop is the right approach for preventing non-permutation inputs from causing an endless swap loop. The checks reject values outside 1..n and duplicates, while preserving the existing empty-list behavior. The added doctests cover both failure modes.

I also checked the PR metadata: the change is limited to the two relevant files, with no unrelated file modifications.

One limitation: the PR body claims the targeted doctests and Ruff check were run, but the currently exposed commit status only shows pre-commit.ci - pr passing. I therefore would not treat the full stated test plan as independently verified from the available GitHub checks.

Overall, I found no code-level blocking issue in the diff. Please ensure the stated targeted test commands are represented in CI before merge.

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.

bug(searches): jump_search raises IndexError for empty list input cyclic_sort.py has no input validation, causes infinite loop on invalid input

3 participants