fix(searches): empty jump_search input; validate cyclic_sort - #15147
fix(searches): empty jump_search input; validate cyclic_sort#15147felipeofdev-ai wants to merge 3 commits into
Conversation
fix(sorts): validate cyclic_sort input to prevent infinite loops Fixes TheAlgorithms#15085 Fixes TheAlgorithms#14898
c041e4b to
b80d47d
Compare
10cfe92 to
2fb19fb
Compare
|
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. |
Summary
-1for empty sequences instead of raisingIndexError(Fixes bug(searches): jump_search raises IndexError for empty list input #15085).1..nbefore sorting; raiseValueErroron duplicates or out-of-range values to prevent infinite loops (Fixes cyclic_sort.py has no input validation, causes infinite loop on invalid input #14898).Test plan
python -m doctest searches/jump_search.py sorts/cyclic_sort.pyuvx ruff check sorts/cyclic_sort.py searches/jump_search.pyjump_search([], 5)returns-1cyclic_sort([1, 1, 2])raisesValueError