Skip to content

Harden binary-family searches against unsorted input#14

Merged
Nullkernel merged 1 commit intomainfrom
codex/harden-binary-search-implementations
Apr 5, 2026
Merged

Harden binary-family searches against unsorted input#14
Nullkernel merged 1 commit intomainfrom
codex/harden-binary-search-implementations

Conversation

@Nullkernel
Copy link
Copy Markdown
Owner

Motivation

  • Prevent incorrect results or undefined behavior when binary-family algorithms are run on unsorted arrays by enforcing a clear input contract.
  • Align behavior across non-linear search implementations so callers see consistent semantics and messages instead of implicit mutations (e.g., implicit sorting).

Description

  • Implemented a validation-and-reject policy in Binarysearch.java, Uniform_binarysearch.java, Interpolationsearch.java, and Fibonaccisearch.java to verify that input arrays are sorted and to return early with a clear message when they are not.
  • Added an isSorted(int[]) helper to each updated class to perform the sortedness check.
  • Updated user prompts to explicitly request array elements in non-decreasing (sorted) order and removed the implicit Arrays.sort(arr) from Fibonacci search so indices remain meaningful.
  • Ensured scanners are closed on both early-return failure paths and normal exit paths.

Testing

  • Ran compilation: javac Searching-algorithms/Binarysearch.java Searching-algorithms/Uniform_binarysearch.java Searching-algorithms/Interpolationsearch.java Searching-algorithms/Fibonaccisearch.java, which completed successfully.

Codex Task

@Nullkernel Nullkernel merged commit 9fd2c2d into main Apr 5, 2026
1 check passed
@Nullkernel Nullkernel deleted the codex/harden-binary-search-implementations branch April 6, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant