Last answered:

21 Oct 2020

Posted on:

07 Aug 2020

0

The Python Programmer Bootcamp: Binary search video is all wrong.

def binary_search(item, my_list):
found = False
first = 0
last = len(my_list) -1

while first <= last and found == False:
midpoint = (first + last)//2
if my_list[midpoint] == item:
found = True
else:
if my_list[midpoint] < item:
first = midpoint + 1
else:
last = midpoint - 1
return found

test = [6,5,8,2,3,45,87,23,70]
print(linear_search(87,test))
print(linear_search(88,test))

this is the code from the video.
first the function you run is not the binary_search but the linear_search function we wrote the last lesson.
second the binary_search only works on "sorted arrays". so if you runned the code:

test = [6,5,8,2,3,45,87,23,70]
print(binary_search(8,test))

it wouldn't work.
the binary_search code is not wrong. but the explanation is not enough and you never even runned the correct function.

1 answers ( 0 marked as helpful)
Instructor
Posted on:

21 Oct 2020

0
Hi Matan,  thanks for reaching out! You're absolutely right and you can now download the updated Notebook file with the resources for the lecture.   Best,  The 365 Team

Submit an answer