#69 Python Tutorial for Beginners | Binary Search Using Python

preview_player
Показать описание
Python Tutorial to learn Python programming with examples

Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Editing Monitors :

Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

Remember Binary sort function will be performed on the sorted list, so before executed def binarySeach(list, n): just type list.sort()
your program will run correctly..

ShahzaibElahi
Автор

The best video in this python series. : -)

Dhanush-zjmf
Автор

Finally I understood after your video. Too good 👍

mehulaggarwal
Автор

# in binary search the values of an array must be sorted
"""step 1 - set the lowerBound and upperBound
step 2 - find a min index i.e lowerBound + upperBound / 2
step 3 - now we have to check that the mid value is same or not with the value we are seaching for
step 4 - next change your lowerBound or upperBound
4.1 - the value we are searching for is smaller or bigger than the mid value
4.1.1 - if your value is smaller change the upperBound to midindex
4.1.2 - if your value is bigger change the lowerBound to midindex
step 5 - again find a mid value
repeat step 4 """
pos = -1
def search(arr, n):
lB = 0
uB = len(arr)-1
while lB <= uB:
mid = (lB+uB) // 2
if arr[mid] == n:
globals()['pos'] = mid
return True
else:
if arr[mid] < n:
lB= mid+1
else:
uB = mid-1
return False

arr = [4, 7, 8, 12, 45, 99]
n = int(input("Enter a number: "))
if search(arr, n):
print("Found at ", pos)
else:
print("Not Found")

sidharth
Автор

Great videos sir ! Only I had to point out one correction, I think when we relocate the lowerBound or UpperBound, it should be lowerBound=mid+1 and upperBound=mid-1 .
You've mentioned it in later part though . For anyone having doubt with the initial part of video, hope this comment helps :p

anushkashah
Автор

Navin, I love your videos. I had just one question in this video and also in bubble sort and linear search videos. What if you have a list of some values which appear more than once. Also will this procedure ignore any string values inside the list or do we have to implement an exception handling ourselves?

HappyAnimalsD
Автор

Naveen, I haven't found even native english speakers to explain as intuively as you do in this video. Thanks a lot for what you do.

vishakarudhra
Автор

Thank you so much. This really helped me out.

JimmyJim
Автор

If you know the element you're looking for exsists in the list, and you just want to find the index for it. Is there any benefit to binary searching, or can you simply .index()? For example, I have a list of dates in the format '2020-03-01' and I want to find the index of the current days date. Is binnary searching more time efficient? Thanks

Cop
Автор

A great video
Something that helped me with my homework, thought it will take an entire day

somnvm
Автор

I like this active and simple way of teaching, , , anyways thank you sir, , ,

DilanTech
Автор

ur videos make so simple learning python. thanks.

akshayshinde
Автор

Excellent. I have been revising python concepts last 2 days by watching your videos and learned many new concepts.

arjunanselvam
Автор

Navin, your thought process makes so much sense to me. Thanks for sharing these videos!

blueguru
Автор

Hi Navin sir, my doubt is, the code runs fine for any index position search if we do u = len(list) OR u = len(list) - 1. Why is that?

prasannakatre
Автор

thxx very much fun learning python from you

naveenadhikari
Автор

Sir please do video on threads where 2 threads work together and share data

abharathkannan
Автор

sir thanks for making such amazing videos fan sir

mohammedsamiuddin
Автор

the shifting of lower and upper bound is so easy to understand, and here I was, trying to slice the list a bunch of times...

gkof
Автор

Your videos are far better than others

yashwanthaas