The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

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

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

0
Votes
0
Answer
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.

No answers so far.
×
LAST CHANCE
Ready to Learn Data Science?
50% OFF