I recommend solving binary search problems on Leetcode (leetcode.com/explore/learn/card/binary-search/). Don't read their templates though, they aren't perfect. Start with easy problems: leetcode.com/explore/learn/card/binary-search/125/template-i/951/, leetcode.com/explore/learn/card/binary-search/126/template-ii/947/, leetcode.com/explore/learn/card/binary-search/126/template-ii/949/. You can find C++ and Python codes to some problems in my GitHub repo, github.com/Errichto/youtube/tree/master/lectures/binary-search. Note that some problems aren't same with what I talked about during a lecture. For example, Find Peak Element in Leetcode seems harder because the function can have multiple peaks. Huge thanks to Reddy for making captions!
Thank you for the wonderful video. It really help me understand the algorithm better. It will be really great if you can do more videos like this where you go over other data structures and algorithms that are most used especially in interviews.
The most important lesson I learned from this video, don't bother updating low/high conditionally, stick with only one binary search template (for 99% of the cases), and use a variable instead to store pivot position as per your condition. It makes every binary problem 10x easier for me.
I finally understood the idea of "getting a better answer". Most binary implementation on the Internet look like hacky, with people incrementing or decrementing the mid by one to get a desired answer. Thanks a bunch.
Thanks Errichto! This was by far the best explanation I've seen/heard of binary search! I thought I had understood it before but this has deepened my understanding profoundly. The length is also good. I think it would help us all a lot of you did more videos like this to really get a deep understanding of algorithms.
@@devendrasingh4776 Bruh! That was just an example 😂. I meant he is not teaching the concept. He is teaching practical implementation. Like after this, some people might see binary search with a totally different perspective.
@@SumitBadsara exactly . I am that guy who has changed perspective. Now i think like more of finding that condition rather than blindly dividing into half. All thanks to this guy.. 😊
Thank you! This is one of the best algorithm video with clarity and great explanations I saw so far! I learned so much, plz keep update these algorithm videos, maybe the more general ones that people used everyday. I think that might have a bigger impact for the general public :)
Hands down the best explanation I've come across on BS yet. Looking at it from a a PoV of prefixes and suffixes was really eye opening, and has made solving some problems suuper easy. Thank you!!!
Thank you Errichto for the top-notch pedagogical content. Your techniques in this video helped me in one particular question in a technical interview for Amazon. I didn't receive the final offer, however it was a great experience thanks to you!
Very intuitive explanations. I have never come across keeping an "ans" variable but it makes so much sense. Much easier to understand than other solutions!
Really awesome lecture. Thanks a lot for all the time you put into preparing this stuff. All those hours of BPS surely do pay off. Can't wait to learn more things from you.
Właśnie znalazłem twój kanał po obejrzeniu twojego wywiadu z Joma. Bardzo dokładnie i prosto wszystko tłumaczysz. Zdecydowanie najlepszy kanał z algorytmami jaki dotychczas widziałem!! Keep it up!
Congrats, Kamil, for a great video! With every video i learn more and more. Please make more videos like this, where you explain other popular algorithms. (segment trees, graph theory, string algoritms like KMP, etc.)
I feel this is the best binary search visualisation and strategy explanation because one thing is correct, it is a simple algorithm but at the same time it is very easy to write a buggy code for it. Thank you
This year I was studying mathematics on university Leiden and I dont know but my interest to learn mathematics declined so much just by attending school. A month ago I dropped out and found your videos and now I fell in love with competitive programming. Thank you so much!
In the sorted rotated array variation. It's safe to say that assume false when element at mid is greater than "or equal to" the last element. Only greater than would fail for the case when the smallest number is repeated. Eg. 6, 7, 9, 9, 15, 19, 2, 2, 3
This was great. Will you be covering data structures/algorithms not typically found in undergrad books? Square root decomposition and seg trees for example.
I recommend solving binary search problems on Leetcode (leetcode.com/explore/learn/card/binary-search/). Don't read their templates though, they aren't perfect.
Start with easy problems: leetcode.com/explore/learn/card/binary-search/125/template-i/951/, leetcode.com/explore/learn/card/binary-search/126/template-ii/947/, leetcode.com/explore/learn/card/binary-search/126/template-ii/949/.
You can find C++ and Python codes to some problems in my GitHub repo, github.com/Errichto/youtube/tree/master/lectures/binary-search.
Note that some problems aren't same with what I talked about during a lecture. For example, Find Peak Element in Leetcode seems harder because the function can have multiple peaks.
Huge thanks to Reddy for making captions!
Thanks!
I was trying to apply that ans = mid template for finding the minimum element in a sorted array. Was I doing something wrong?
Thank you for the wonderful video. It really help me understand the algorithm better. It will be really great if you can do more videos like this where you go over other data structures and algorithms that are most used especially in interviews.
4:20 Since (L+R)/2 would overflow, shouldn't (L/2) + (R/2) work though?
what would be the eps value in sqrt() function?
The most important lesson I learned from this video, don't bother updating low/high conditionally, stick with only one binary search template (for 99% of the cases), and use a variable instead to store pivot position as per your condition. It makes every binary problem 10x easier for me.
Thanks so much for such videos. A lot of people struggle badly to be good at competitive programming. You make their life easy. Thanks again.
adding to that, you are a very humble person as well.
Hi, Sarvesh from India
Please keep making such Conceptual videos.
Best lecture on binary search implementation, thanks Errichto.
Period
@@AnkitJosh .
@@AnkitJosh comment
that observation where we can generalize the problem to a prefix of Falses and a suffix of Trues was mindblowing. thank you so much!
Great video! I can finally write binary search without hesitating or wasting time debugging a +1/-1 issue.
I finally understood the idea of "getting a better answer". Most binary implementation on the Internet look like hacky, with people incrementing or decrementing the mid by one to get a desired answer. Thanks a bunch.
Thanks errichto for the well prepared material and thanks Reddy for captions!!
It is so far the best binary search video I have watched on UA-cam,Thank You very much....
The best half hour that I spent in entire 2020
Thanks Errichto! This was by far the best explanation I've seen/heard of binary search! I thought I had understood it before but this has deepened my understanding profoundly. The length is also good. I think it would help us all a lot of you did more videos like this to really get a deep understanding of algorithms.
This is the actual binary search! Not just (L+R)/2 . Thanks for these examples. Keep making such videos. Love from India🇮🇳.
Well it is correct but will give int overflow . So it better to be on safer side . Thats it .
@@devendrasingh4776 Bruh! That was just an example 😂. I meant he is not teaching the concept. He is teaching practical implementation. Like after this, some people might see binary search with a totally different perspective.
@@SumitBadsara exactly . I am that guy who has changed perspective. Now i think like more of finding that condition rather than blindly dividing into half. All thanks to this guy.. 😊
Thanks Errichto, after watching this video now I have a better understanding of binary search and its applications.
All the things I learnt over weeks in a small 30 min video, thanks errichto!
Thank you! This is one of the best algorithm video with clarity and great explanations I saw so far! I learned so much, plz keep update these algorithm videos, maybe the more general ones that people used everyday. I think that might have a bigger impact for the general public :)
Hands down the best explanation I've come across on BS yet. Looking at it from a a PoV of prefixes and suffixes was really eye opening, and has made solving some problems suuper easy. Thank you!!!
Thank you very much. Please continue to make videos covering the fundamentals. Loved the clear, concise and comprehensive presentation.
Thank you so much errichto! Please continue to make such comprehensive tutorials!!
Thank you Errichto for the top-notch pedagogical content. Your techniques in this video helped me in one particular question in a technical interview for Amazon. I didn't receive the final offer, however it was a great experience thanks to you!
That was great, thank you. More videos like this, where you introduce a concept, and then provide related examples, would be amazing.
I was really struggling with binary search, but your video made all the difference, thanks Kamil!
Very intuitive explanations. I have never come across keeping an "ans" variable but it makes so much sense. Much easier to understand than other solutions!
Really awesome lecture. Thanks a lot for all the time you put into preparing this stuff. All those hours of BPS surely do pay off. Can't wait to learn more things from you.
This channel is a goldmine!
Glad I found this before getting my cs major
You cannot find a lecture on binary search better than this!
Thank you for the comprehensive explanation of binary search! I really didn't know it was so powerful before!
This is by far the best video for binary search. Kudos to your amazing work, Errichto!
Właśnie znalazłem twój kanał po obejrzeniu twojego wywiadu z Joma.
Bardzo dokładnie i prosto wszystko tłumaczysz. Zdecydowanie najlepszy kanał z algorytmami jaki dotychczas widziałem!! Keep it up!
Congrats, Kamil, for a great video! With every video i learn more and more. Please make more videos like this, where you explain other popular algorithms. (segment trees, graph theory, string algoritms like KMP, etc.)
You should do more of these lectures, like sorting algos and data structures
Thanks so much for the clear and concise material! I hope you keep making these.
Great video! You helped better understand binary search, but more importantly, its implications. You are a great teacher. Thank you.
I feel this is the best binary search visualisation and strategy explanation because one thing is correct, it is a simple algorithm but at the same time it is very easy to write a buggy code for it.
Thank you
This is the best lecture on binary search. Thank you Errichto
Usually really smart people like u are not known for their great teaching skills...
U really changed that!
This was great. Helped me learn a lot. I would be looking forward to more such sessions.
World class video must watch everyone👍
Thanks a lot man! I was struggling to get a hold of all the variations. You made it so simple!
Thanks for sharing! Your explanations are clear and concise. Also congrats on recent win!
Hey Errichto, after watching this video , i have solved my all doubts related to binary search.Thanks for the amazing explanation.Love from India
Best video on binary search I have seen till now
Thanks for the great lecture! Instead of a template, you gave me a proper way to think of the algorithm.
I loved your lecture, as a teacher/trainer of coding, you are best. Thanks man.
This year I was studying mathematics on university Leiden and I dont know but my interest to learn mathematics declined so much just by attending school. A month ago I dropped out and found your videos and now I fell in love with competitive programming. Thank you so much!
what a brilliant idea of thinking binary search problems as elements of search space being T or F !
Wow he has explained the concept of discrete binary search beautifully. The topcoder tutorial was good but this video covers the topic really well
Best explaination of binary search in youtube. Thanks a lot!
Excellent way to cover Binary Search using a systematic way.. Thanks a lot
What a great lecture, now binary search is Perfectly clear.
Thanks a lot sir
Wow, super great video. Thanks for making this errichto.
Hi Errichto this is an amazing lecture! Thank you so much and please keep up the great work!
it was very good, I thought I new binary search but after watching this video I found out much more. It was really helpful. Thank you
Thanks man u made my interview preparation much easier
Thanks a lot for the clear explanation
thank you so much errichto, ur explanation was awesome
now i understand binary search better
Excellent -- thanks for the correct way to calculate the midpoint in binary search.
One of the best lectures on binary search
need second part of this lecture as soon as possible , its a humble request from the fan side
This is legit the best binary search video anyone has made 👏
I watched your video and I got explained my topic what I wanted for. thank you so much sir 🙏
Pls do a leture on basic greedy and DP
I'm planning a lecture on dp, actually. It should be out soon.
Well explained, Errichto. Clean and Simple.
This is so awesome! Thank you so much @Errichto!
It's really safe zone but didn't think before. Thanks. L + (R-L)/2 = (2L + R - L) /2 = (L + R)/2
I think 2L and L+R will overflow
@@GreatKrish1 they were probably demonstrating how L + (R-L)/2 and (L + R)/2 is the same but does not overflow
@@zafirhasananogh2421 Yeah that's what I wrote
I have lost from rotated array, till then it was awesome!
Thanks errichto for your efforts and clear presentation.
Great video, love it, you are very good at making complex problems seem very simple!
greetings from Mexico! those videos are really cool, thanks for all the effort put on those.
This is a MUST watch vid on binary search!!
"The study from 1988 showed that only one in four textbooks has a correct implementation..."
In the sorted rotated array variation. It's safe to say that assume false when element at mid is greater than "or equal to" the last element. Only greater than would fail for the case when the smallest number is repeated. Eg. 6, 7, 9, 9, 15, 19, 2, 2, 3
Let's keep it binary with 2 words: PURE GOLD!
Please, do a lecture on Graph Algorithms. Also, thanks for this video.
Covers a lot of important observation and pattern in binary search.
CP God for a reason.. Love your efforts. Love from India
Very cool content! Thank you!
Waiting for more videos...
Lovely classic lecture , mesmerized by explanations , thanks alot ❤️
Thank you very much Errichto, really appreciate it. ❤️
Your ways so easy to understand. thank you Eric so much!!!
This video was really helpful to me. Thanks for making such good content.
Really appreciate of your videos !! very clear explanation
Thank you!
Best lecturer I have seen. Thanks!
Great work bro. Thank you for uploading such a great content.
Just clicked before thinking let's watch something might come up .
Best lecture on binary search
This was great. Will you be covering data structures/algorithms not typically found in undergrad books? Square root decomposition and seg trees for example.
yes, i also say so.
Yes, I plan both sqrt deco and seg trees :) More video ideas here: github.com/Errichto/youtube/wiki/Video-ideas
@@Errichto Please make a video on segment and fenwick trees.
thanks a lot enrichto!! beautifully explained!!
Thank you so much sir. Countering problems with that T...F was quite interesting I will try sometimes
I wish I watched this video earlier. The True & False pattern is so helpful!!!
Great learned some new applications of binary search
Most informative binary search tutorial ❤️
Thanks, Please make videos on educational round problems.
Awesome video lad, great explanations!
Everyone else: Use (l+r)/2 to find the middle element. No problem at all.
Errichto: Never use this formula xD
Thanks for the video! Came here from Joma's vid
Man You are the best Teacher !!
Thank you very much. It's easy after watching your video.
Trying desperately to wrap my head around rotated, sorted arrays haha. Anyways great video!
amazing lecture. Thanks !