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!
@earth200105 жыл бұрын
Thanks!
@swagatochatterjee71044 жыл бұрын
I was trying to apply that ans = mid template for finding the minimum element in a sorted array. Was I doing something wrong?
@jdhp36964 жыл бұрын
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.
@Sehyo4 жыл бұрын
4:20 Since (L+R)/2 would overflow, shouldn't (L/2) + (R/2) work though?
@roufshaik35304 жыл бұрын
what would be the eps value in sqrt() function?
@kshitijpatil20193 жыл бұрын
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.
@maximus1172 Жыл бұрын
Very insightful I must say
@naughtyrishan5 жыл бұрын
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.
@musicfan16954 жыл бұрын
adding to that, you are a very humble person as well.
@sarveshdubey93475 жыл бұрын
Hi, Sarvesh from India Please keep making such Conceptual videos.
@medievalogic3 жыл бұрын
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.
@rajbapat56075 жыл бұрын
Great video! I can finally write binary search without hesitating or wasting time debugging a +1/-1 issue.
@sauravpaul41315 жыл бұрын
Best lecture on binary search implementation, thanks Errichto.
@AnkitJosh4 жыл бұрын
Period
@mujtabahussain70153 жыл бұрын
@@AnkitJosh .
@joshiakhil0073 жыл бұрын
@@AnkitJosh comment
@TheGanesamurthi4 жыл бұрын
The best half hour that I spent in entire 2020
@dharmanshah12395 жыл бұрын
Thanks errichto for the well prepared material and thanks Reddy for captions!!
@nijikatherock2 жыл бұрын
that observation where we can generalize the problem to a prefix of Falses and a suffix of Trues was mindblowing. thank you so much!
@AniketKumar-xg3ky5 жыл бұрын
It is so far the best binary search video I have watched on KZbin,Thank You very much....
@shubhamagrawal24075 жыл бұрын
Thanks Errichto, after watching this video now I have a better understanding of binary search and its applications.
@rohan8arora5 жыл бұрын
All the things I learnt over weeks in a small 30 min video, thanks errichto!
@Nyquiiist3 жыл бұрын
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!!!
@SumitBadsara5 жыл бұрын
This is the actual binary search! Not just (L+R)/2 . Thanks for these examples. Keep making such videos. Love from India🇮🇳.
@devendrasingh47764 жыл бұрын
Well it is correct but will give int overflow . So it better to be on safer side . Thats it .
@SumitBadsara4 жыл бұрын
@@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.
@devendrasingh47764 жыл бұрын
@@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.. 😊
@prabhatsharma2845 жыл бұрын
You cannot find a lecture on binary search better than this!
@dcodernz5 жыл бұрын
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.
@franceshe13505 жыл бұрын
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 :)
@srikanthkoraveni82105 жыл бұрын
Thank you very much. Please continue to make videos covering the fundamentals. Loved the clear, concise and comprehensive presentation.
@shroud33545 жыл бұрын
World class video must watch everyone👍
@dominikdabrowski70824 жыл бұрын
I was really struggling with binary search, but your video made all the difference, thanks Kamil!
@de_naenae3 жыл бұрын
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!
@codepractices75 жыл бұрын
Thank you so much errichto! Please continue to make such comprehensive tutorials!!
@anweshbhattacharya80174 жыл бұрын
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!
@Woef7183 жыл бұрын
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!
@kaushaldawra35273 жыл бұрын
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
@codexhammered0073 жыл бұрын
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
@pradyundevarakonda68494 ай бұрын
This channel is a goldmine! Glad I found this before getting my cs major
@BGivo5 жыл бұрын
That was great, thank you. More videos like this, where you introduce a concept, and then provide related examples, would be amazing.
@gupta_samarth5 жыл бұрын
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.
@iamtrash2884 жыл бұрын
Thank you for the comprehensive explanation of binary search! I really didn't know it was so powerful before!
@adityarai8963 Жыл бұрын
This is by far the best video for binary search. Kudos to your amazing work, Errichto!
@shroudyboi56734 жыл бұрын
Wow he has explained the concept of discrete binary search beautifully. The topcoder tutorial was good but this video covers the topic really well
@darshantawte74354 жыл бұрын
Best video on binary search I have seen till now
@sameerbhatti3633 жыл бұрын
Great video! You helped better understand binary search, but more importantly, its implications. You are a great teacher. Thank you.
@anands94074 жыл бұрын
Usually really smart people like u are not known for their great teaching skills... U really changed that!
@kpopisthebestful5 жыл бұрын
You should do more of these lectures, like sorting algos and data structures
@nayanchudasama20143 жыл бұрын
What a great lecture, now binary search is Perfectly clear. Thanks a lot sir
@rahulsbhatt3 жыл бұрын
This is legit the best binary search video anyone has made 👏
@rajansaharaju14275 жыл бұрын
It's really safe zone but didn't think before. Thanks. L + (R-L)/2 = (2L + R - L) /2 = (L + R)/2
@GreatKrish17 ай бұрын
I think 2L and L+R will overflow
@zafirhasananogh242124 күн бұрын
@@GreatKrish1 they were probably demonstrating how L + (R-L)/2 and (L + R)/2 is the same but does not overflow
@lovleshbhatt77974 жыл бұрын
need second part of this lecture as soon as possible , its a humble request from the fan side
@psibarpsi Жыл бұрын
This was great. Helped me learn a lot. I would be looking forward to more such sessions.
@raselhasan24333 жыл бұрын
I loved your lecture, as a teacher/trainer of coding, you are best. Thanks man.
@himanshulal4454 Жыл бұрын
Excellent way to cover Binary Search using a systematic way.. Thanks a lot
@matiyasyohannes55022 жыл бұрын
This is the best lecture on binary search. Thank you Errichto
@amritbhardwaj993 жыл бұрын
This is a MUST watch vid on binary search!!
@wizardOfRobots3 жыл бұрын
Thanks for the great lecture! Instead of a template, you gave me a proper way to think of the algorithm.
@lpdc97675 жыл бұрын
Thanks so much for the clear and concise material! I hope you keep making these.
@Rich655015 жыл бұрын
Excellent -- thanks for the correct way to calculate the midpoint in binary search.
@doejohn5637 Жыл бұрын
what a brilliant idea of thinking binary search problems as elements of search space being T or F !
@jannoszczyk51325 жыл бұрын
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!
@priyanandshukla83883 жыл бұрын
One of the best lectures on binary search
@namanbudhiraja67564 жыл бұрын
Hey Errichto, after watching this video , i have solved my all doubts related to binary search.Thanks for the amazing explanation.Love from India
@rehanakhter48133 жыл бұрын
Best explaination of binary search in youtube. Thanks a lot!
@literallynoone20932 жыл бұрын
Thanks a lot man! I was struggling to get a hold of all the variations. You made it so simple!
@sanddevelopers5 жыл бұрын
Thanks a lot for the clear explanation
@alexneagu44665 жыл бұрын
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.)
@kairatopa95644 жыл бұрын
Thanks man u made my interview preparation much easier
@chandup832Ай бұрын
I have lost from rotated array, till then it was awesome!
@yawningcats3 жыл бұрын
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
@KarthikKarthik-el5hh2 жыл бұрын
thank you so much errichto, ur explanation was awesome now i understand binary search better
@1338392973 жыл бұрын
Let's keep it binary with 2 words: PURE GOLD!
@saitama-fv6my2 жыл бұрын
I watched your video and I got explained my topic what I wanted for. thank you so much sir 🙏
@davidjiang79294 жыл бұрын
Thanks for sharing! Your explanations are clear and concise. Also congrats on recent win!
@icenberg59084 жыл бұрын
Thanks errichto for your efforts and clear presentation.
@blu50375 жыл бұрын
Wow, super great video. Thanks for making this errichto.
@mehedihasanjoy87265 жыл бұрын
Pls do a leture on basic greedy and DP
@Errichto5 жыл бұрын
I'm planning a lecture on dp, actually. It should be out soon.
@abhishekdhok52453 жыл бұрын
CP God for a reason.. Love your efforts. Love from India
@pradiptarakshit354 жыл бұрын
Please, do a lecture on Graph Algorithms. Also, thanks for this video.
Hi Errichto this is an amazing lecture! Thank you so much and please keep up the great work!
@yilinma83674 жыл бұрын
I wish I watched this video earlier. The True & False pattern is so helpful!!!
@SushantKumar-iy4is4 жыл бұрын
Well explained, Errichto. Clean and Simple.
@cccctainvista4 жыл бұрын
Great video, love it, you are very good at making complex problems seem very simple!
@thuanvo92833 жыл бұрын
Your ways so easy to understand. thank you Eric so much!!!
@omti5 жыл бұрын
Very cool content! Thank you! Waiting for more videos...
@abhishekgaurgaur3 жыл бұрын
Thank you very much Errichto, really appreciate it. ❤️
@SuperArjun115 жыл бұрын
This was great. Will you be covering data structures/algorithms not typically found in undergrad books? Square root decomposition and seg trees for example.
@ajr1791ze5 жыл бұрын
yes, i also say so.
@Errichto5 жыл бұрын
Yes, I plan both sqrt deco and seg trees :) More video ideas here: github.com/Errichto/youtube/wiki/Video-ideas
@kushagrasahni97084 жыл бұрын
@@Errichto Please make a video on segment and fenwick trees.
@koocheukkeijacky97045 жыл бұрын
Really appreciate of your videos !! very clear explanation
@Errichto5 жыл бұрын
Thank you!
@ivanleon61643 жыл бұрын
greetings from Mexico! those videos are really cool, thanks for all the effort put on those.
@adityakajale44033 жыл бұрын
Best lecture on binary search
@darshpatel83854 жыл бұрын
This video was really helpful to me. Thanks for making such good content.
@rohanvtk4 жыл бұрын
2:46 the correct formula and the reason why :)
@areebwadood62735 жыл бұрын
Great learned some new applications of binary search
@barakode4144 жыл бұрын
Thank you very much. It's easy after watching your video.
@abdurrahaman3884 жыл бұрын
Most informative binary search tutorial ❤️
@laskdkmgful5 жыл бұрын
Best lecturer I have seen. Thanks!
@__-to3hq5 жыл бұрын
"The study from 1988 showed that only one in four textbooks has a correct implementation..."
@beanlighter94914 жыл бұрын
Thank you so much sir. Countering problems with that T...F was quite interesting I will try sometimes
@primerevan84033 жыл бұрын
Just clicked before thinking let's watch something might come up .
@murahat983 жыл бұрын
Everyone else: Use (l+r)/2 to find the middle element. No problem at all. Errichto: Never use this formula xD
@avisekshaw47484 жыл бұрын
Great work bro. Thank you for uploading such a great content.
@bharat_india12 Жыл бұрын
In this video first find the range which satisfy which is true and not satisfied which is false and applied binary search in the range to find last true or first true of first false or last false . Other case in which only one point is answer use mid and check goes to left or right or current mid is answr to return.
@teezp12490a5 жыл бұрын
Thanks for the video! Came here from Joma's vid
@rajgarg88835 жыл бұрын
Thanks, Please make videos on educational round problems.
@omanshsharma67962 жыл бұрын
thanks a lot enrichto!! beautifully explained!!
@aabhassaxena24905 жыл бұрын
The overflow you talked about in the java library Will have no affect in competitive coding bcoz there the constraints are small so we will not have array of such big size and therefore overflow will never occur
@Errichto5 жыл бұрын
1) We will eventually work with arrays of size 2e9. It might already happen in unusual contests like Distributed Code Jam. 2) The array is not always given explicitly - examples are computing floor(sqrt(x)) or interactive problems. It's better to use binary search that will always work.
@yamisekai4 жыл бұрын
Thank you for sharing your knowledge, great video!