Skip to content

fix: code quality improvements in searches and sorts#14565

Open
JiayangLai wants to merge 1 commit intoTheAlgorithms:masterfrom
JiayangLai:fix/code-quality-improvements
Open

fix: code quality improvements in searches and sorts#14565
JiayangLai wants to merge 1 commit intoTheAlgorithms:masterfrom
JiayangLai:fix/code-quality-improvements

Conversation

@JiayangLai
Copy link
Copy Markdown

Summary

  • binary_search.py: Fix return type check in exponential_search - was checking is None but function returns -1 when not found
  • linear_search.py: Use ValueError instead of generic Exception for proper exception handling
  • merge_sort.py: Avoid O(n) pop(0) operations by using index-based merging for better performance

Changes

  • searches/binary_search.py: Fixed exponential_search return value check
  • searches/linear_search.py: Changed Exception to ValueError
  • sorts/merge_sort.py: Replaced pop(0) with index tracking to avoid O(n) shift operations

Test plan

  • Run doctests on all modified files

🤖 Generated with Claude Code

- binary_search.py: fix return type check in exponential_search (is None -> == -1)
- linear_search.py: use ValueError instead of generic Exception
- merge_sort.py: avoid O(n) pop(0) operations by using index-based merging

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants