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 Binary Search in Code

Ingrid Davis
Ingrid Davis
4,000 Points

Confused on looping back through after 'first' becomes 5

I understand that the first becomes 5 in the elif statement. Then we loop back through with our new first value. I don't understand how we arrive at 6 for the midpoint value. If 5(first) + 8 (last) = 13 --> //2 then how do we know to round up or down to get 6 as the midpoint?

Any help to further break down this process would be helpful. Thank you!

1 Answer

// in python is a floor division operator, i.e. it always rounds down.