Тёмный

Binary Search Algorithm in 100 Seconds 

Fireship
Подписаться 3,3 млн
Просмотров 563 тыс.
50% 1

Binary Search is an algorithm that can find the index of an element in a sorted array data structure. You've likely used Binary Search it in everyday life without even realizing it.
#compsci #programming #100SecondsOfCode
🔗 Resources
Binary Search en.wikipedia.o...
Big-O in 100 Seconds • Big-O Notation in 100 ...
Recursion in 100 seconds • Recursion in 100 Seconds
🔥 Get More Content - Upgrade to PRO
Upgrade to Fireship PRO at fireship.io/pro
Use code lORhwXd2 for 25% off your first payment.
🎨 My Editor Settings
- Atom One Dark
- vscode-icons
- Fira Code Font
🔖 Topics Covered
- Binary Search in JavaScript
- How does binary search work?
- When was binary search first used?
- How code recursive binary search?
- Big-O Time complexity of binary search

Опубликовано:

 

12 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 1,1 тыс.   
@mr.anderson5077
@mr.anderson5077 2 года назад
Hey Jeff, Please cover all the topics from data structures and algorithm. Thanks
@Ma1ne2
@Ma1ne2 2 года назад
Yes plz!
@SheikhAmeen
@SheikhAmeen 2 года назад
Yesss! Like this comment, get to the top!
@auroreis2308
@auroreis2308 2 года назад
Yessssss fully agree
@flyte9844
@flyte9844 2 года назад
YES PLEASE :D
@gopalkmrr
@gopalkmrr 2 года назад
Yes
@discarded1669
@discarded1669 2 года назад
Do a series of these different Algorithms.. Helps immensely in quick revising them for tests..
@WTHBrou
@WTHBrou 2 года назад
Yes, please. I've been having a hard time implementing variations of DFS and BFS graph algos.
@marcelsantee1809
@marcelsantee1809 2 года назад
@@WTHBrou I keep failing hard at graphs interview, I second that
@Ruf4eg
@Ruf4eg 2 года назад
Yes, please.
@6little6fang6
@6little6fang6 2 года назад
MOAR ALGORITM PLS
@JettoDz
@JettoDz 2 года назад
Yes. A series, then put them in a playlist. CS 101. You'll get tons of students into it. I can already forsee teachers using Fireship videos as introductions for every (available) algorithm.
@taylorcarroll6487
@taylorcarroll6487 2 года назад
More algorithms please, I was just looking this up yesterday and found this video explains it more clearly than others because you clearly explain WHY we would use this rather than just parroting how to do it out of textbook.
@m1rac1e
@m1rac1e 2 года назад
If you're a CS student/beginner learning data structures & algos for the first time, I cannot recommend "A common-sense guide to data structures & algorithms" enough. It's a textbook that is focused on explaining the base concepts in plain English to a beginner. It goes in-depth without overwhelming you. Provides exercises, examples, & diagrams. Book saved my life freshman year of CS.
@shreehari2589
@shreehari2589 2 года назад
@@m1rac1e bro i am gonna be in freshmen year in August, can you please give me the link to download it.
@nateo7045
@nateo7045 2 года назад
I would like more algorithms because I like algorithms, but this is a hardly revolutionary video. Here's to generic praise 😂
@m1rac1e
@m1rac1e 2 года назад
@@shreehari2589 look up textbook piracy, can't link it because youtube filter blocks me. gotta use ur brain.
@rajikkali2381
@rajikkali2381 2 года назад
@@shreehari2589 try z-lib
@StuartLoria
@StuartLoria 2 года назад
This is amazing. I would call the series “demystifying Algorythms”, or “computer archeology”, or “understand the technical interview”
@arossfelder
@arossfelder 2 года назад
That's a great idea you got here ...
@123456crapface
@123456crapface 2 года назад
aaaand thats why no one asked you
@freakymidget
@freakymidget 2 года назад
A playlist of common interview questions would be a godsend
@sauravbv
@sauravbv 2 года назад
I finished my engineering course long back, but would pay you to watch data structures and algorithms explained in such a nice way!
@koolamusic_
@koolamusic_ 2 года назад
bru
@DodaGarcia
@DodaGarcia 2 года назад
This was so awesome, as a self-taught developer I never got to learn most theoretical things like this, and it definitely has an effect on my problem solving
@Chiefsosa17
@Chiefsosa17 2 года назад
Well, I knew binary search already. But this dictionary anology was just amazing.
@Aresous
@Aresous 2 года назад
i think cs50 does this
@Chapali9a
@Chapali9a 2 года назад
Holy moly! Ive never seen anyone explain it as simple as this. Please do more data structures and algorithms stuff. Thank you
@binzek
@binzek 2 года назад
What a miracle. My computer science teacher taught us linear search today. And will teach binary search tomorrow. I got it easy 😊
@mephi5t0
@mephi5t0 2 года назад
The code shown actually have a bug. When it was written back in the day it was not a problem. Now of your search array has billion elements the sum of integers may overflow and become negative. The new proper way to avoid going out of bounds of the integer to calculate mid point is int mid = low + ((high - low) / 2); This was a bug in Java for 9 years
@Dr.Schnizzle
@Dr.Schnizzle 2 года назад
This is actually really important. I’ve gotten dinged for this.
@AkaiKnight
@AkaiKnight 2 года назад
To be fair, he did say the code was in JavaScript. But this is still an important insight you’re giving
@jandresshade
@jandresshade 2 года назад
No only that, this kind of iteration is really limited in JS (in fairnes JS is not a declarative lenguaje and has the while loop for this kind of problems), you going to get a "Maximum call stack size exceeded error" before getting this bug.
@svenniepennie4237
@svenniepennie4237 2 года назад
@@jandresshade Why would you get a maximum call stack size exceeded error?
@vectoralphaSec
@vectoralphaSec 2 года назад
I don't get it. Can you explain?
@18.j
@18.j 2 года назад
Love to see more algorithms videos! 👏🏻
@conceptioned
@conceptioned 2 года назад
More algorithms in under 100 seconds like these, please! This was explained way more succinctly than a regular class would have done.
@mridulbarman027
@mridulbarman027 2 года назад
Need many many more videos please ❣️ Sir taught in class many times but never able to explain like this. Thank you ❤️
@alichamas63
@alichamas63 2 года назад
I really love these videos. My favourite dev content on RU-vid. Perfect balance of knowledge, time, humour, and impact.
@aschmelyun
@aschmelyun 2 года назад
Definitely keep making these. I'm a full-stack developer, but missed out on a lot of the 'low-level' knowledge like algorithm design and Big O notation. This video was incredible!
@jesusrojas5262
@jesusrojas5262 2 года назад
This is the first time that I truly understood the Binary Search algorithm and how to implement it using recursion in just 2 minutes. Awesome!
@heathenmonk1249
@heathenmonk1249 2 года назад
Yes, continue with more algorithms, this was so easy to understand, thanks!
@JohnSnow-gi7iv
@JohnSnow-gi7iv 2 года назад
We need more like these algorithms
@sirgrem2988
@sirgrem2988 2 года назад
Man, you've come at a perfect timing for this one! Would love to see more about algorithms.
@elijahmandeville8475
@elijahmandeville8475 2 года назад
This made more sense to me than when I learned about it during a 2 hour lecture. Would love to see algorithms more
@abdousidiya2130
@abdousidiya2130 2 года назад
I’d appreciate if you make a series about data structure and algorithms. Your explanation is really helpful! Thanks:)
@chiroyce
@chiroyce 2 года назад
With Jeff's videos we can speedrun learning!
@niteshsethi4091
@niteshsethi4091 2 года назад
Algorithm holds a massive part in today's technical world. Apart from dev tools like react, redux, and all including devops, algorithm is something we all get to ask even in interview. I appreciate the work you have done yet and doing continuously to get us know what that technology actually means and when should we have it in use. Other data structures and algorithms are welcome from my side. We all need it.
@alansaldivares
@alansaldivares 2 года назад
This is pure gold, and yes, the crowd cries out desperately for more videos of algorithms and data structures. Keep it up man, thanks!
@colinzollars2017
@colinzollars2017 2 года назад
Please do more Algorithms! I'm practicing Leetcode so this video is incredibly helpful in explanation. Time Complexities are a harder concept for me so this helped explain that a little more.
@LalanDesai
@LalanDesai 2 года назад
Make a whole playlist like 'Algorithms in a nutshell' or something like that and explain all those algorithms out there in 100 seconds.
@multiarray2320
@multiarray2320 2 года назад
next video: how to reverse a linked list.
@pyanimate1493
@pyanimate1493 2 года назад
Hi Fireship, I am learning data structures and algorithms. Please continue. I actually like the way you simplify things.
@reandov
@reandov 2 года назад
Hey Jeff, great video! How about a new series where you show most known algorithms in 100 seconds? That would be great!
@normankidhoma9897
@normankidhoma9897 2 года назад
Wow. The simplicity is amazing. Would love more of these. Thanks
@y404
@y404 2 года назад
hey this was really informative and interesting to watch all while being entertaining because of how good your animations are. please keep doing more of these 👍
@typicalgamer9064
@typicalgamer9064 2 года назад
Videos about popular and lesser known algorithms would be great content. Would watch them all!
@dadidus1
@dadidus1 2 года назад
I would use the .indexOf() function instead of a for loop
@M9625Rahul
@M9625Rahul 2 года назад
Thats Language feature not available in all languages and you aren't allowed to do that
@roy_2470
@roy_2470 Год назад
I know this is a relatively old video, but I love these algorithm videos, please return with more of these in depth algorithm videos if you feel like it:)
@erfanexp
@erfanexp 2 года назад
I wish I didn't know how binary search works so that I could enjoy this video more
@JoseMoreno-uc2qz
@JoseMoreno-uc2qz Год назад
What took my intro to data structures/algorithms professor weeks to each you succinctly explained it in less than 3 minutes. I appreciate your work a lot!
@redaaaa
@redaaaa 2 года назад
typo at 1:05 (search)
@a3animations
@a3animations 2 года назад
Once again this man has made me understand code so much better
@arkhamian7586
@arkhamian7586 2 года назад
It would be great if you could cover the most common algorithm and data structures topics that are asked in interviews. Also, topics like solid principles, deadlocking, etc. Your videos make a great refresher for any concept without being boring. In any case, thank you for the great work!
@shreym03
@shreym03 2 года назад
This is a good video. But I see one flaw in it. You haven't explained the fact that binary searches work only in an environment where everything is sorted
@jef777
@jef777 2 года назад
0:39 "given a sorted array"
@kolegowiewtrasie4054
@kolegowiewtrasie4054 2 года назад
in a 100s video every word counts
@aletarin10
@aletarin10 2 года назад
Man, this 100 seconds videos on algorithms are a pretty nice refresh. Would be good also for people who wants to learn this kind of things, but find themselves overwhelm with books definitions. Nice job as always !
@lightning_11
@lightning_11 Год назад
Who's gonna tell him that these videos are all 150 seconds long?
@whateverittakes1547
@whateverittakes1547 Месяц назад
wait let me knock his door....
@XinWongDigital
@XinWongDigital 23 дня назад
i guess O(1.5n) is still O(n)😂
@wizarddev3506
@wizarddev3506 2 года назад
Quite an interesting algorithm and certainly one important for all developers, regardless of language or field. The video explains it quite well. Keep up the good work Fireship!
@krishnasahu8553
@krishnasahu8553 2 года назад
First
@funwithalbi2425
@funwithalbi2425 2 года назад
didn’t ask + don’t care + ratio
@negaaa5080
@negaaa5080 2 года назад
Ratio
@Fireship
@Fireship 2 года назад
🥇 Gold!
@unaisulhadi9102
@unaisulhadi9102 2 года назад
Yes, Please to a complete series on all algorithms and data structures, it'll be really helpful.
@jewpcabra666
@jewpcabra666 2 года назад
love it! these are great for practicing for coding interviews - especially if you cover more complex topics that are hard to visualize (dynamic programming, fast/slow pointers, loops etc)
@max0223
@max0223 2 года назад
Amazing explanation for a common problem that is very helpful. Please do more of this!
@onefloatavenue
@onefloatavenue 7 месяцев назад
I hadn’t been able to picture divider-and-conquer algorithms for weeks, until this video. Thank you so much.
@Kayzewolf
@Kayzewolf 2 года назад
Your method of teaching both in the "to the point" time constraint and the visuals have really helped me better understand what a lengthy memorization-centric course fails to do.
@dz3petto100
@dz3petto100 2 года назад
its amazing how most channels take almost10 minutes to explain these things and here it's done in 2 minutes.
@JayJames
@JayJames 2 года назад
I already know this will be a great mini series!
@shaft2112
@shaft2112 2 года назад
Four years of CompSci Degree, three years in the industry and I just got a grippy example for a recursion. Thank you a lot, Jeff!
@musclechicken9036
@musclechicken9036 2 года назад
Hey I learned about these from computer science and didn’t understand a single thing but your 100 seconds made me understand everything, thanks I genuinely needed this 😁
@pranavsetpal
@pranavsetpal 2 года назад
Woah, that's pretty cool! I knew how to do it but by using a recursive function it was definitely a much different approach I hadn't seen before. Looked so much better than a binary search algorithm I had made earlier.. The explanation was so much simple and straight forward from the one in my textbook. This is absolutely amazing!
@andresramos7965
@andresramos7965 2 года назад
A series about different algorithms would be great
@brandonsayring
@brandonsayring 2 года назад
This is the best explanation of binary search algorithms I've seen.
@RandomDude889
@RandomDude889 2 года назад
I absolutely need more algorithm oriented content this is fantastic.
@6peekaboo9
@6peekaboo9 2 года назад
You should make more vids on Algos, this one was really good.
@ziyon25
@ziyon25 2 года назад
I don't comment much, but this is probably the most useful and efficient 100 seconds that I can ever give to RU-vid. Please make more of these!
@StellarWeb008
@StellarWeb008 2 года назад
We want hundreds of videos like this discussion about popular algorithms and implement them in our favourite javascript
@arytiwa4351
@arytiwa4351 2 года назад
Expecting a full animated Data structures and algorithms course on this channel Please dont disappoint
@jazzmaster89
@jazzmaster89 2 года назад
Please continue to release these videos. Algos/DS are always top of mind for most folks interview prep, amazing stuff as always.
@smaybius
@smaybius 2 года назад
A good example of binary search is in a variant of insertion sort. Its comparisons are always O(n log n) but the sort is still average and worst case O(n^2), but a disadvantage over regular (linear search) insertion sort is that it's bad on low disparity because the best case is O(n log n) instead of O(n), meaning that linear insertion is better for cleanup such as in introsort (C++/C#'s standard library sorting algorithm)
@mavyfaby
@mavyfaby 2 года назад
I wish this episode exist before we had a binary search topics. To be honest, this is a lot easier to grasp than our previous discussion.
@SirDamatoIII
@SirDamatoIII 2 года назад
Love Zuc shaking his head when you failed the interview at 0:48 - that was brilliant!
@shreehari2589
@shreehari2589 2 года назад
Yes we would like to see more algorithms videos and also data structures as well
@jacksingermusic
@jacksingermusic 2 года назад
This is amazing!! U gotta make more of these!!! Btw: typo at 1:14
@5014eric
@5014eric 2 года назад
Looking up in a dictionary we usually (in the first 1-3 iterations) save time by going not to the middle of the remaining search space, but depending on where the value falls in the remaining range. This works because of what we know about distribution of words.
@CodingWithLewis
@CodingWithLewis 2 года назад
Amazing video as always. Implementing most of my loops with this will probably speed up my code 🤯
@brianevans4
@brianevans4 2 года назад
Would love to know more about the ancient Babylon algorithm and it's usage
@emilianogarcialopez3591
@emilianogarcialopez3591 2 года назад
Love this series on algorithms! You should do more
@iskandar-9726
@iskandar-9726 Год назад
1:20 Just a quick note here, It follows the Decrease & Conquer Approach (Decrease By Factor) not the divide & C since we solve the main problem directly by solving the sub problem.
@bigmackdombles6348
@bigmackdombles6348 2 года назад
You are a genius at teaching, I will watch and use whatever content you make, including more algorithm vids.
@antonionotbanderas9775
@antonionotbanderas9775 4 месяца назад
This channel is so good it's raising my ADD everywhere else.
@Wizzardo
@Wizzardo 2 года назад
This is way better than my college professor sending some rando's video. Would love to see you discussed algorithms more!
@83yWasTooShort
@83yWasTooShort 2 года назад
Just learnt this in Computer Science, this helps my knowledge even further
@roulzhq
@roulzhq 2 года назад
Nice video! I like this more than going over really complex subjects in 100 seconds because you can barely scratch the surface there. This now really explained a lot of the approach already. Question by the way: where do you get your emoji pictures like the pointing hand from?
@psychoclips6817
@psychoclips6817 2 года назад
You explain that in 2 minutes better than any of my professors could in a half hour. I would really love to see how you present dynamic programming, maybe with a genetic sequence alignment example.
@azzazkhansiddiqui
@azzazkhansiddiqui 2 года назад
Love your short videos and if you explain data structures and algorithms like this it would help me a lot in my university!
@KiraKillerBoo
@KiraKillerBoo Год назад
Yes a series of these different Algorithms would be great
@nanotichorizon9644
@nanotichorizon9644 2 года назад
Damn Jeff, to explain Recursion AND BS in 100s is just a testament to your skills dude.
@ericpeck7858
@ericpeck7858 2 года назад
Great video! We would love to see videos like this for all sorts of algorithms. Even compare and contrast different algorithms(space & time complexity, etc).
@HazemTamimi
@HazemTamimi 2 года назад
Yes, we need to see more videos about algorithms and data structures please!
@irunmik
@irunmik 2 года назад
The flipping-through-a-dictionary analogy is so good, wish I had this video when I was interviewing!
@yousefelsayed4203
@yousefelsayed4203 2 года назад
would love more videos about algorithms like this video concise and to the point and with an example to understand. Keep it going
@JoeyFenny
@JoeyFenny 2 года назад
Yes please! Great job at simplifying it. Way easier to understand than via leetcode
@dennishalo369
@dennishalo369 2 года назад
Hi, on one of your videos, you shared that you have been working independently for more than 10years. Could you kindly make a video about your journey as developer/programmer? Thanks.
@lakshman587
@lakshman587 2 года назад
Please do 100 seconds of all the data structures related algorithms that exist in the world!
@januszwitkowski878
@januszwitkowski878 2 года назад
That's a really cool format for algorithms showcases! Keep it up!
@dlysele
@dlysele 2 года назад
There should be an entire series of 2~ minutes of videos on algorithms like this.
@mohamedsaleh5970
@mohamedsaleh5970 2 года назад
Greate idea to make algorithms series. keep doing it and thanks for your wonderful content and simplified description.
@TomDoesTech
@TomDoesTech 2 года назад
This is awesome! More data structures and algo videos please :)
@suhailxyz1582
@suhailxyz1582 2 года назад
a playlist of data structures and algs videos from Fireship would be a lifesaver
@pedgarcia
@pedgarcia 2 года назад
Short and sweet (as usual). Please, keep them coming!
@bigbrogaming9237
@bigbrogaming9237 2 года назад
Please upload more videos on algorithms and also if you recommend any resources to learn practically about the algorithms would be a big help
@illogicalconsistency
@illogicalconsistency 2 года назад
I’m liking where this is going. As a beginner game dev, I think it would be awesome to learn some more on some path finding algorithms
@curiosity6969
@curiosity6969 2 года назад
Very informative! Need more videos on algorithms!!
@karanhotwani5179
@karanhotwani5179 2 года назад
Need more 100 seconds of algorithms. So much fun to learn it this way.
@sostenemunezerobagira8358
@sostenemunezerobagira8358 2 года назад
Well explained, Please continue making algorithm videos
@Amir-bz1fk
@Amir-bz1fk 2 года назад
We wanna see more videos about algorithms on this channel
Далее
Cypress in 100 Seconds
2:31
Просмотров 379 тыс.
How to NOT Fail a Technical Interview
8:26
Просмотров 1,4 млн
100+ Computer Science Concepts Explained
13:08
Просмотров 2,5 млн
Big-O Notation - For Coding Interviews
20:38
Просмотров 467 тыс.
10 Math Concepts for Programmers
9:32
Просмотров 1,9 млн
Quest To Find The Largest Number
11:43
Просмотров 413 тыс.
Binary Search Algorithm - Computerphile
18:34
Просмотров 160 тыс.
I tried 10 code editors
10:28
Просмотров 3 млн
Binary Search in Java - Full Simple Coding Tutorial
17:48
Sorting Algorithms Explained Visually
9:01
Просмотров 534 тыс.
Binary Search Animated
7:00
Просмотров 30 тыс.