Skip to content

Fixed recursion error in binary_search_by_recursion - #246

Merged
harshildarji merged 1 commit into
TheAlgorithms:masterfrom
antfitch:antfitch-patch-1
Jan 31, 2018
Merged

harshildarji merged 1 commit into
TheAlgorithms:masterfrom
antfitch:antfitch-patch-1

Conversation

@antfitch

Copy link
Copy Markdown
Contributor

In binary_search_by_recursion, if you search array for a value that does not exist, you will get this error:

RecursionError: maximum recursion depth exceeded in comparison

To fix this, first check to make sure that the value is between left and right points like this:

if (right < left):
    return None

A similar construct has already been applied to binary_search, but did not exist in the recursive alternative.

In binary_search_by_recursion, if you search array for a value that does not exist, you will get this error:
RecursionError: maximum recursion depth exceeded in comparison

To fix this, first check to make sure that the value is between left and right points like this:
    if (right < left):
        return None

A similar construct has already been applied to binary_search, but did not exist in the recursive alternative.
@harshildarji
harshildarji merged commit 4085de4 into TheAlgorithms:master Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants