Skip to content

Fix matrix binary search at row starts - #15549

Open
sean0407 wants to merge 1 commit into
TheAlgorithms:masterfrom
sean0407:codex/fix-matrix-search-row-start
Open

sean0407 wants to merge 1 commit into
TheAlgorithms:masterfrom
sean0407:codex/fix-matrix-search-row-start

Conversation

@sean0407

@sean0407 sean0407 commented Oct 10, 2026 •

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

mat_bin_search(3, [[1, 2], [3, 4]]) currently returns [-1, -1] instead of [1, 0]. After the first row is searched, the loop condition matrix[index][0] < value stops when the target equals the first element of the next row, so that row is never searched. Using <= includes that boundary row.

A previous proposal for the same one-line correction, PR #15548, was closed by algorithms-keeper because that author already had multiple open PRs. It did not merge, and the upstream source still has the bug.

Verification

  • Reproducible input and expected result: mat_bin_search(3, [[1, 2], [3, 4]]) -> [1, 0].
  • The current source-level trace shows the < condition stops at row 1 before the binary search call; the updated <= condition reaches that call.
  • GitHub compare confirms exactly one algorithm file changed, with 1 addition and 1 deletion.

Checklist

  • I have read CONTRIBUTING.md.

  • I know that pull requests will not be merged if they fail the automated tests.

  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.

  • All new Python files are placed inside an existing directory. (No new files.)

  • All filenames are in lowercase and use underscores. (No new files.)

  • All function parameters and return values are annotated. (No signature changes.)

  • All new algorithms include a reference URL. (No new algorithm.)

  • If this pull request resolves an issue, include its closing keyword. (No linked issue.)

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass labels Oct 10, 2026

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

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant