Skip to content

Split exponential search recursion into a flat int-only core - #15389

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:exponential-search-wrapper-core
Sep 21, 2026
Merged

cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:exponential-search-wrapper-core

Conversation

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Follow-up to #15384, per @cclauss's preference for the wrapper/core shape over the None sentinel on the recursive path.

What changed

binary_search_by_recursion in searches/exponential_search.py now:

  • does the right = len(...) - 1 defaulting once, in the outer function, and
  • delegates the actual recursion to a nested _search(left, right) core whose left/right are always concrete int indices.

The recursion is now flat: the window can only shrink, there is no sentinel to re-expand it, so the runaway recursion that #15384 fixed (searching for an item below sorted_collection[0]) stays fixed by construction rather than by a None-check inside the recursive call.

This mirrors the wrapper/core structure already used by the sibling searches/binary_search.py (its binary_search_by_recursion wraps a nested _binary_search_recursive helper), so the two files read consistently.

The public signature is unchanged (right still defaults to the last index), and all existing doctests pass.

Verification

  • python3 -m doctest searches/exponential_search.py — 12/12 pass.
  • Fuzzed against ground truth on 200k random cases (lengths 0–10, values incl. duplicates, targets both inside and outside the range, including below the first element and the empty collection): 0 mismatches.

Follow-up to TheAlgorithms#15384. Replace the ``right: int | None`` sentinel on the
recursive path with a thin wrapper that defaults ``right`` once, then
delegates to a nested ``_search(left, right)`` core whose indices are
always concrete ints. This matches the wrapper/core shape already used by
``binary_search.py`` and keeps the recursion flat so the window can only
shrink.
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 21, 2026
@algorithms-keeper

Copy link
Copy Markdown

Closing this pull request as invalid

@priya-sundaram-dev, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines.

If you're facing any problem on how to mark a checkbox, please read the following instructions:

  • Read a point one at a time and think if it is relevant to the pull request or not.
  • If it is, then mark it by putting a x between the square bracket like so: [x]

NOTE: Only [x] is supported so if you have put any other letter or symbol between the brackets, that will be marked as invalid. If that is the case then please open a new pull request with the appropriate changes.

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 21, 2026
@cclauss cclauss reopened this Sep 21, 2026
@algorithms-keeper algorithms-keeper Bot added the enhancement This PR modified some existing files label Sep 21, 2026
@cclauss
cclauss merged commit 6029a91 into TheAlgorithms:master Sep 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files invalid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants