Back to Freecodecamp

Binary Search in Code

curriculum/challenges/english/blocks/algorithms-in-code/binary-search-in-code-video.md

latest516 B
Original Source

--description--

In this video, you will code out the binary search algorithm using Python.

--questions--

--text--

Why was the while first <= last: condition used in the solution?

--answers--

To ensure only the first half of the array is ever checked.


To make the loop run forever until manually stopped.


To skip checking the last element in the search range.


To keep searching while there are still elements in the range and stop when the range is empty.

--video-solution--

4