Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Computer Science Introduction to Algorithms Algorithms in Code Recap: Algorithms in Code

Kareem Jeiroudi
Kareem Jeiroudi
14,984 Points

There's an error in the recursion implementation code

I believe, I've spotted an error in this code, where in the scope of the last if-else statements the function binary_search_recursive(args) is being called instead of recursive_binary_search(args). I hope you fix this soon.

# see the function's name!
def recursive_binary_search(list, target, start=0, end=None):
    if end is None:
        end = len(list) - 1
    if start > end:
        return -1

    mid = (start + end) // 2

    if target == list[mid]:
        return mid
    else:
        if target < list[mid]:
            # see the function called!
            return binary_search_recursive(list, target, start, mid-1)
        else:
            return binary_search_recursive(list, target, mid+1, end)

1 Answer