Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Computer Science Introduction to Algorithms Algorithms in Code Recursive Binary Search

Martin Owaga Mboya
Martin Owaga Mboya
13,595 Points

Recursive Binary Search

Why does he not subtract one from the length of the list like he did in the previous video?

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 33,977 Points

Hi Martin. Great question. In the binary search video he wanted to find the position of the last element in the list. Because lists start at 0 the position is going to be the number of elements - 1. (if there are 10 elements they will be 0 to 9). In this video he just wants to check if the list is empty. He's not looking for the last element. He knows if the length equals 0 then the list is empty. Hope this helps Martin.