Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners
@priscillacheng443 жыл бұрын
I love your witty quips! "If you click 'solution' too early, you will get a computer virus" lol I find myself looking forward to them every video. Thanks for making this!
@codebasics3 жыл бұрын
ha ha .. glad you liked them :) my sense of humor is not that great but I am trying to make it better
@2pizen3 жыл бұрын
@@codebasics i find them extremely amuzing too, they crack me up!! You could improvize further ;)
@gauravjoshi356619 күн бұрын
@@codebasics I wait till the end, just to hear those threats, XD
@thud93factory513 жыл бұрын
You are one of the best tutors on youtube for Computer Science, love and respect from Bangladesh.
@akashp48633 жыл бұрын
underrated video. you're the best teacher for me in Data structures and Algorithm. the way you think is the way i also think so i end up with doubts like why and hows, which you clear at the exact same time. Thank you
@codebasics3 жыл бұрын
Akash thanks for this excellent feedback
@pavanpatro53563 жыл бұрын
Firstly, simplistic yet awesome!! explanation.. A scenario expressing out of curiosity (more from performance perspective) : "Let's assume a scenario, where the input list of numbers doesn't follow any particular order i.e. ascending/descending.. then sorting of the list first, prior to performing the binary search enhances the code performance.
@lisamathur92065 ай бұрын
Another approach to solve with bin_serarch_rec - def bin_search_rec(numbers, key): l = 0 u = len(numbers) - 1 mid = (u+l)//2 if numbers == []: return False if numbers[mid] == key: return True if numbers[mid] > key: return bin_search_rec(numbers[0:mid],key) if numbers[mid] < key: return bin_search_rec(numbers[mid+1 : ],key)
@tharindusathsara3414 Жыл бұрын
Really very happy about finding such an obvious and understood funny video series about data structures and algorithms. Everything is 100% clear with deeply explained theories and well-understood practicals. Also, the exercise series with the videos are highly appreciated. Dear sir thank you so much for the fantastic video series. ❤💖
@sachinladhad54632 жыл бұрын
Dear Sir, You are the best teacher, I am really enjoy videos and learning at the age of 45.
@codebasics2 жыл бұрын
Great. I wish you all the best
@snehakurhade87653 жыл бұрын
The recursion code errors because when you call the function in the main, the right index is provided as len(number_list) which is 8 in your case. Instead the right index should be initialized with (len(number_list)-1). Thus your right index now correctly points to location 7 which consists of value 67
@hemachandiran39843 жыл бұрын
def binary_search(list,target): first=0 last=len(list)-1 while first
@Anilsree-064 жыл бұрын
Thank you @codebasics, requesting you to kindly continue this series of Data Structures and Algorithms in Python sir. This is really good and very helpful for beginners who aim to go from zero to hero. Thank you once again sir.
@codebasics4 жыл бұрын
Sure, second algorithm video on bubble sort is coming tomorrow
@winnienakimuli2102 жыл бұрын
Thank you so much Sir for this series of videos, they have helped a lot being a newbie at these topics, and the debugging tip is everything, thank you!
@zubair4172 Жыл бұрын
Hello @codebasics thanks for very good explaination but i want to add one thing in "binary_search_recursive" function you don't need to handle if mid_index >= len(numbers_list) or mid_index < 0: return -1 just provide right_index correct like you are providing right_index = len(numbers_list) but it should be len(numbers_list)-1
@ThaoPhuong-ln9vc3 жыл бұрын
Need help understanding big O: 1. What is the average time complexity of the 2nd exercise solution? My answer is O(log n + left + right), where left + right
@kameshparashar4 жыл бұрын
Waiting for this video from a long time ❤️
@codebasics4 жыл бұрын
Hope you enjoyed it! Second video on bubble sort is coming tomorrow
@globemasterybusinessformul73523 жыл бұрын
Your explanation is very clear and practical
@codebasics3 жыл бұрын
thanks
@jykw17173 жыл бұрын
Sir you getting error at the end because you didn't len(numbers_list)-1 for recursive binary search input?
@kkkbuta54 ай бұрын
Thank you, I was questioning what went wrong because i could not find fault in the algorithm
@AACREATIONS20003 жыл бұрын
best and best lecture ever i have seen till now..thank you sir
@codebasics3 жыл бұрын
I am happy this was helpful to you.
@riteshojha4607 Жыл бұрын
Best video for binary search
@Whitris6 ай бұрын
Kudos for your courses! Just a thing: it would be better to use time.perf_counter() inside the time_it decorator, instead of time.time(). You would get a much better resolution, avoiding the "0.0 mil sec" measurement for the binary search
@abhishekkumaryadav36474 жыл бұрын
please continue this series...you explanation is great.
@codebasics4 жыл бұрын
yes. second video coming up tomorrow on bubble sort
@jyotikagrover45272 жыл бұрын
In FIND_ALL_OCCURANCES exercise if you remove "else: break" from the code then it'll print all the occurances regardless of where the element is present
@anirbanc882 жыл бұрын
i love the exercises!
@rafeeqsyedamjad88754 жыл бұрын
Sir plz continue this series ds and algo with python online we have fewer resources to follow ds and algo with python it will be really helpful to crack product based companies for data science. upload videos related to this as much as possible
@ganeshtalari75554 жыл бұрын
Yes you are right, they are very few videos about data structures using python.
@codebasics4 жыл бұрын
yes I have resumed the series. Second video on bubble sort is coming tomorrow.
@shubhamkumarshukla60024 жыл бұрын
@@codebasics sir please make few more videos on graph I think graph in python had no resources on internet please make few more videos
@harris72944 жыл бұрын
@@codebasics sir that error was about index out of limit bcoz initially you gave right index as len(list) it should have been len(list) - 1
@abduchadili5691 Жыл бұрын
Very good series, reminded me my college Data Structures & Algorithms, we used Pascal language back then. The only issue is when you show PyCharm it is very blurry and a bit eye hurting.
@andrewmukare34332 жыл бұрын
I loved this tutorial! You are a great teacher! Thank you!
@sanjuroy85423 жыл бұрын
The Way You teach us its really tremendous ... Love You 3000 sir can you share the ppt!!!
@rohitchitte56143 жыл бұрын
def recursive_binary_search(lis,key,start,end): if start middle: start = middle + 1 return recursive_binary_search(lis,key,start,end) else : end = middle - 1 return recursive_binary_search(lis,key,start,end) # this approach worker for me .
@zack176 Жыл бұрын
Is this for exercise
@markmariscal53974 жыл бұрын
Yes!!!! My fav algorithm quick run time yet simple implementation
@codebasics4 жыл бұрын
Glad you like it!
@rogerthat7190 Жыл бұрын
Thank you so much sir
@jeenieb62552 ай бұрын
The recursive function is repeatedly throwing an error of ' name binary_search_recursive is not defined'. Could you please guide me on how to resolve this? I have a sorted array in place & correct indentation as well.
@bhaskark14852 жыл бұрын
Thank you brother
@romanhudec47193 жыл бұрын
Awesome explanation! 👍
@codebasics3 жыл бұрын
Glad you liked it
@mount88572 жыл бұрын
Hello there :) A great tutor indeed! In this video, the binary search algorithm only works on integer lists. Could you improvise it to work on strings too. I got you an assignment too😂
@hellohello10063 жыл бұрын
Hello Sir! This is my take on your exercise, do you think this is too complicated?: def binary_search_multi(num_list, num_to_find, left, right, occurences=[]): if right < left: return mid_index = (left + right) // 2 if mid_index >= len(num_list) or mid_index < 0: return mid_element = num_list[mid_index] if mid_element == num_to_find: if str(mid_index) not in occurences: occurences.append(str(mid_index)) binary_search_multi(num_list, num_to_find, left, right-1) binary_search_multi(num_list, num_to_find, left+1, right) elif mid_element < num_to_find: left += 1 binary_search_multi(num_list, num_to_find, left, right) else: right -= 1 binary_search_multi(num_list, num_to_find, left, right) return occurences
@NaveenKinnal-k1e Жыл бұрын
Had you put the right index as "len(numbers_list) - 1" in line 51 of the recursive program, you would not have got the error "list out of range" error :)
@tripathi51744 жыл бұрын
Thankyou so much for making it sir.
@codebasics4 жыл бұрын
It's my pleasure
@niyatham85252 жыл бұрын
do you assume the list is sorted? and then perform a binary search?
@codebasics2 жыл бұрын
yes binary search works only on sorted list. If list is not sorted you need to sort it first
@joxa6119 Жыл бұрын
Question, so by using this algorithm, we assumed that the list numbers is in sorted right? Otherwise could it work?
@alexlu29 ай бұрын
Yes, we are assuming that the list numbers is in sorted order. It would not work otherwise because if the list was not in order, you cannot guarantee that the numbers on the left or right is definitely bigger or smaller than your target number.
@lordofperfection552821 күн бұрын
but in recursion the array must be always sorted
@atleefernandes2642 жыл бұрын
@codebasics How to use binary sort to search a key vakue pair in a list of dictionaries? Its possible through Linear Search however if I want to make it search faster what do I use?
@MaheshKumar-sc9bo2 жыл бұрын
thank u sir
@meralmaradia47742 жыл бұрын
Hello Sir, can you please create a video developing of project using only DSA ?
@abhishekdobliyal71784 жыл бұрын
Sir in recursive function why r_index
@ayanchowdhury67324 жыл бұрын
Please make a series on NLP
@codebasics4 жыл бұрын
yes that is in my plans
@ayanchowdhury67324 жыл бұрын
@@codebasics thanks...waiting eagerly
@meherprudhvi93682 жыл бұрын
What if array is not sorted
@pankajbhatt73732 жыл бұрын
if you debug this code , you will see control is moving to else condtion when list remain [16,17] , which should not happen. can anyone tell me why ? def binarySearch(myList,element): '''This will take only sorted list''' print(myList) mid = len(myList)//2 print(mid) if mid==0 : return -1 elif element == myList[mid]: return mid else: while element < myList[mid]: binarySearch(myList[:mid], element) while element > myList[mid]: binarySearch(myList[mid:], element) if __name__== '__main__': myList = [11,12,13,14,15,16,17] print('list on which item is serched',myList,end=' '*3) element = 17 print(f'Element to be searched {element}',end=' '*3) pos = binarySearch(myList,element) print(f'{element} is present at {pos} position ')
@Alex-xh2tb2 жыл бұрын
9:50 "you want to find a mid number so my mid number is ... this! right??" where is any tiny explanation for this ??? Thank you!
@akashp48633 жыл бұрын
Binary search will only work in ordered list right?
@codebasics3 жыл бұрын
Yes
@sumitraj55293 жыл бұрын
Can you please share PPT too?
@piyushjain12374 жыл бұрын
Bhai mein coding beginner hu toh kya mujhe C language sikhni chaiye kya
@codebasics4 жыл бұрын
Not necessary. Start with python directly.
@piyushjain12374 жыл бұрын
@@codebasics Thank you sir
@machinelearninggeek3 жыл бұрын
y not use sort function inside all function to make better code
@farhathabduljabbar98794 жыл бұрын
Hi sir how often do you upload?
@codebasics4 жыл бұрын
few videos a week
@sainikhilesh34673 жыл бұрын
awesome content. can anyone please share a link to this playlist for all the data structures video you have uploaded sir
@codebasics3 жыл бұрын
go to youtube and search "Codebasics data structures tutorial playlist"
this is my code before seeing yours , thanks bro def binary_search(number_list , find_number , right = None, left = None): if right is None: r = len(number_list) - 1 #this will be used only in the first call else: r = right if left is None: l = 0 #this will be used ony in the first call else: l = left mid =int(l + (r-l)/2) #base condition if number_list[mid] == find_number: return mid #because in this cas mid is the index you are searching for. if r < l: return -1 #means that this number does not exist, #itteration behavior if number_list[mid] < find_number: l = mid + 1 return binary_search(number_list , find_number , r , l ) elif number_list[mid] > find_number: r = mid - 1 return binary_search(number_list , find_number , r , l)
@bharatkasera82814 жыл бұрын
Please increase your codes size
@codebasics4 жыл бұрын
Sure. Took care of it in next video
@tradingtexi2 жыл бұрын
Right index at line 54 should be len - 1
@ganeshtalari75554 жыл бұрын
Hello sir, I request you to use light mode than dark mode because dark mode is too dull to watch.