Skip to content

Guard interpolation search denominator when range endpoints are equal#10

Merged
Nullkernel merged 1 commit intomainfrom
codex/update-interpolationsearch-for-denominator-guard
Apr 5, 2026
Merged

Guard interpolation search denominator when range endpoints are equal#10
Nullkernel merged 1 commit intomainfrom
codex/update-interpolationsearch-for-denominator-guard

Conversation

@Nullkernel
Copy link
Copy Markdown
Owner

Motivation

  • Prevent a divide-by-zero when computing the interpolation pos in interpolationSearch by handling the degenerate case where arr[lo] == arr[hi] before evaluating the formula.

Description

  • Added an early if (arr[lo] == arr[hi]) branch inside interpolationSearch(int arr[], int lo, int hi, int x) that returns lo when that value equals x and returns -1 otherwise, and left the existing recursive interpolation flow unchanged for non-degenerate ranges.

Testing

  • Attempted to compile with javac Searching-algorithms/Interpolationsearch.java, and compilation failed due to a pre-existing public-class/filename mismatch (DS_Interpolationsearch vs Interpolationsearch.java).

Codex Task

@Nullkernel Nullkernel merged commit 42f0a6b into main Apr 5, 2026
1 check passed
@Nullkernel Nullkernel deleted the codex/update-interpolationsearch-for-denominator-guard branch April 6, 2026 06:36
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