Binary Search in Java - Full Simple Coding Tutorial

  Рет қаралды 106,327

Coding with John

Coding with John

Жыл бұрын

Full tutorial on Binary Search in Java!
☕ Complete Java course: codingwithjohn.thinkific.com/...
What is Binary Search? How does it work, why is it useful, and how do you implement your own version of a Binary Search in Java?
We'll learn all about Binary Search, why it's faster than other search algorithms, and walk through a full implementation from scratch.
SOURCE HERE:
Regular implementation: drive.google.com/file/d/1eMdY...
Recursive implementation: drive.google.com/file/d/1Pii8...
Learn or improve your Java by watching it being coded live!
Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
Let me know what else you'd like to see!
Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
📕 THE best book to learn Java, Effective Java by Joshua Bloch
amzn.to/36AfdUu
📕 One of my favorite programming books, Clean Code by Robert Martin
amzn.to/3GTPVhf
🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
www.audibletrial.com/johnclean...
🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
bit.ly/3QPNGko
📹Camera I use for recording:
amzn.to/3wlXcmR
🎙️Microphone I use (classy, I know):
amzn.to/3AYGdbz
Donate with PayPal (Thank you so much!)
www.paypal.com/donate/?hosted...
☕Complete Java course:
codingwithjohn.thinkific.com/...
codingwithjohn.com

Пікірлер: 174
@dannyj1832
@dannyj1832 Жыл бұрын
My man, we were just covering this in college this week and you happen to be much better at explanations than our professor. You're a legend!
@theseriousaccount
@theseriousaccount Жыл бұрын
College makes more money the longer it takes, it feels like an expensive scam because it is. Learning is best done elsewhere.
@programmingwithnurulhuda
@programmingwithnurulhuda Жыл бұрын
@@theseriousaccount It's always good to learn something.
@frankiia7507
@frankiia7507 9 ай бұрын
tell your professor that face to face
@RishiRajxtrim
@RishiRajxtrim 7 ай бұрын
Yes, 100 points!
@kritibrotodatta5172
@kritibrotodatta5172 6 ай бұрын
Why do I have to learn this in class 10 😭
@jasonmilton7158
@jasonmilton7158 Жыл бұрын
I’m currently a CS student at UofSC Columbia and YOU played a major role in me getting an A in my first Java class and it looks like you’re also gonna play a major role in me passing the second one. I know when I get my degree you will deserve half the credit good sir. Each of your videos are easily more valuable than a week of in class lectures! Thank you
@martinrombach2666
@martinrombach2666 Жыл бұрын
Dude you are by far the best online Java teacher I've come across. So good at explaining things. You deserve more views!
@artem2055
@artem2055 Жыл бұрын
i was waiting for it! Please do more videos on algorithms and problem solving in general
@nenuanenenuane6645
@nenuanenenuane6645 Жыл бұрын
+1
@abhiram2369
@abhiram2369 Жыл бұрын
+2
@programmingwithnurulhuda
@programmingwithnurulhuda Жыл бұрын
@@nenuanenenuane6645 It's always good to learn something.
@programmingwithnurulhuda
@programmingwithnurulhuda Жыл бұрын
@@abhiram2369 It's always good to learn something.
@nenuanenenuane6645
@nenuanenenuane6645 Жыл бұрын
@@programmingwithnurulhuda It's always good to learn something.
@ruvvier1509
@ruvvier1509 Жыл бұрын
This is such a good timing to what I am learning in class right now in college. Thank you John!
@koikoi7666
@koikoi7666 Жыл бұрын
I'm a Senior Dev in Java and I just discovered your videos this week. Even though i'm experienced in the language I feel like I still learn things from watching your content, the way you explain things is incredibly easy to grasp. Please keep making more content, I think you are much better than other channels or even paid courses I have taken in the past.
@yaroslavpanych2067
@yaroslavpanych2067 22 күн бұрын
Pray your boss doesn't discover this comment, you will be demoted to juniors at best!
@fardovav1
@fardovav1 Жыл бұрын
So well explained. Thank you John for coding and explaining each step. Much better than our professor could do!
@MariaRuiz-qm5ql
@MariaRuiz-qm5ql Жыл бұрын
Every time I need to understand something better I go to KZbin hoping that you’ve covered it …🙏 Thank you so much!!
@hashantha_lk
@hashantha_lk Жыл бұрын
The best explaining ever ! Clarity is top notch John ! Sending gratitude from SriLanka! ❤
@simonrozendal7542
@simonrozendal7542 11 ай бұрын
Wow especially with a lot of data, binary search goes really vast and saves a lot of time and energy. thank you John.
@andreadiotallevi5780
@andreadiotallevi5780 Жыл бұрын
Such an excellent communicator - I wish to become as articulate as you. Amazing video!
@mastershonobi110
@mastershonobi110 Жыл бұрын
Thanks John for making these vids; we appreciate your time and effort(s).
@chulsooslaugh1209
@chulsooslaugh1209 Жыл бұрын
Your explanations are easy to understand. It might be your voice or your choice of words but whatever it is, I'm thankful that I am able to fully grasp the concept more easily this time compared to when I took it 2 semesters ago. Looking forward to more videos in the future!
@fruttoo
@fruttoo Жыл бұрын
One video watched, and boom! I became your subscriber. You''re really good with explanations. Congrats!
@abuiman5251
@abuiman5251 Жыл бұрын
Thank you brother! Please don't stop teach us!! God bless you!
@jordanT_alker
@jordanT_alker Ай бұрын
thank you John wonderful video I will use this on my arrays homework, I have some ideas I want to accelerate faster.
@fisheyesarans
@fisheyesarans 9 ай бұрын
Excellent explanation to prepare for a quick interview
@justalilbit8887
@justalilbit8887 Жыл бұрын
Thank you John! I 've been digging into search algorithms, lately. It's great to see you made another great video for it.
@Antonio-kv4lj
@Antonio-kv4lj Жыл бұрын
Started learning Java two weeks ago. Your videos are godsent. Really enjoying them. I would very appreciate if you could make video about managing workspace, projects, files and jdks (jres) in Eclipse. I'm having little trouble with understanding all that. Much thanks.
@aldoumene6201
@aldoumene6201 Жыл бұрын
Yaay love it! more data structures and algorithms please 🙏
@5n2joelemmanuel54
@5n2joelemmanuel54 Жыл бұрын
john is so good at explaining i could binge watch these tutorials and not get bored
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Have at it!
@cloudycode5009
@cloudycode5009 Жыл бұрын
​@@CodingWithJohn Hey man, i love so much your videos im a student, im very excited, i want to see videos about Java GUI awt spring
@amongusztav655
@amongusztav655 Жыл бұрын
Very informative and useful video! Thanks!
@althafazard4232
@althafazard4232 Жыл бұрын
I came to this video just to know you, you are doing great. Your explanation are top notch 🔥
@kristhianortiz151
@kristhianortiz151 Жыл бұрын
I just needed this!!! You're a savior🙏🙏🙏
@elizabeth00653
@elizabeth00653 Жыл бұрын
John I love your Java videos and I really think you're one of the best Java instructors here. I was wondering if you'd consider explaining a Java login project one day with a useful framework, or adding it to your course. That would be so awesome.
@palakkhatri6264
@palakkhatri6264 11 ай бұрын
Amazing, amazing, amazing explaination John!!
@TheTrueType
@TheTrueType Жыл бұрын
Hey John, amazing videos you got here on your channel. You are really playing in an own league, thank you very much helped me a ton! Would you mind doing a video about Iterator aswell?
@fahadgaliwango4502
@fahadgaliwango4502 3 ай бұрын
first attempt and your explanation is very clear
@angelcholakov2670
@angelcholakov2670 Жыл бұрын
Hi John, I really enjoy your videos and the way you explain java in general, so thanks about what You do I am sure loads of people do appreciate it too. I wonder if You have plans to do a video about GUI any time soon? I would love to see one (if this can be done in one video of course) as I am about there in my java study right now
@anishmathew7108
@anishmathew7108 Жыл бұрын
I think you are one of the best Java tutorials videos done in KZbin , can you done tutorials for spring boot
@mouloudguell2763
@mouloudguell2763 Жыл бұрын
very good and clear explanation
@auritro3903
@auritro3903 21 күн бұрын
Damn I have my AP Computer Science A exam tomorrow, you're literally gonna save me :D Thanks!
@benjaminallcock4268
@benjaminallcock4268 Жыл бұрын
Wow, this is awesome explanations, thank you 😃
@williamsun2230
@williamsun2230 Жыл бұрын
Hi John! Love your videos!!! May you make one on the big O notation? Thank you!!!
@adulmdul8939
@adulmdul8939 7 ай бұрын
man you're my rescuer, with sincere love and appreciation
@Tranzin40
@Tranzin40 Жыл бұрын
cool video, it would be cool to hear about faster search and sorting algorithms
@bels1
@bels1 Жыл бұрын
Fantastic explanation, as always! Can you also make a video on the Big O notation?
@Talkatfive
@Talkatfive 2 ай бұрын
Excellent tutorial
@HackBoy_YT
@HackBoy_YT 6 ай бұрын
I am a 10 th grade student from India and dont know binary search thank u so much u deserve millions of subscribers 😊
@oussamaachour1523
@oussamaachour1523 Жыл бұрын
Hey john, thanks for all your tutorials, I would like to see you doing one project with all the oops concepts if that is possible
@RehanAhmad1
@RehanAhmad1 8 ай бұрын
you're my end of search as Java Teacher.. no matter what algorithm we use.. 😀
@SarangSaraf
@SarangSaraf Жыл бұрын
Thank you sooo much. I stopped watching my paid udemy Java courses after I found your channel. REALLY!
@viewer_evgeniy
@viewer_evgeniy 9 ай бұрын
I want to add one important thing about moving high and low pointers to the "right" or "left" of middle pointer (mid+1 or mid-1), it's not just because we want to exclude the number (index) which out of our concern already since we know that if our searched value is not equal to the middle pointer value then there is no reason to ever deal with it again. But doing such kind of things (+1 or -1) ensures that we won't be stuck in an infinite loop (in case your searched value is not presented in the array).
@katiebeers2476
@katiebeers2476 7 ай бұрын
I love your videos, you're fantastic
@kap21031991
@kap21031991 Жыл бұрын
This is very good content and explained in very simple manner!! Please try to create tutorials on concurrency and parallelism.
@DadaKhan1912
@DadaKhan1912 Жыл бұрын
Hi Sir, I have watched every video of Java on your Channel. You are Extremely Super in Teaching Java. And now I want to Learn Java Spring Boot. And I think you are the best teacher to teach Spring Boot in Java. And it is also Tending Technology. So I am telling you to create a playlist on Java Spring Boot. And it will help all the people who want to learn Java Spring Boot. Thank you sir ❤
@rtweakim3122
@rtweakim3122 Ай бұрын
It is very simple and intuitive.😮😮😮😮
@ogfit5448
@ogfit5448 5 ай бұрын
I prefer to make my middle position variable "pointer" but nice simple explanation here!
@fabiofucks1
@fabiofucks1 Жыл бұрын
Great video, waiting for streams and Collections tutorial !!!
@btrsl
@btrsl Жыл бұрын
Great explanation 👌! First time watcher here, will watch more of your content.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Thanks a ton! Hope they're helpful, and let me know if there's anything you'd like to see!
@btrsl
@btrsl Жыл бұрын
@@CodingWithJohn I've watched more than 10 videos of yours in last couple of days. Learned a lot! I'd love to see some Design Patterns content (implemented in java) on your channel.
@btrsl
@btrsl Жыл бұрын
and also congrats on 200k subs!!! 🥳🥳🎉🎉🎉
@enriquepasa
@enriquepasa Жыл бұрын
Thanks for the video
@UCE5YhzPOD
@UCE5YhzPOD Жыл бұрын
From my experience I would recommend to use half-open intervals instead of segments in all algorithms that use intervals like binary search, sortiing, segment tree and so on. It allows to decrease number of +1/-1 in the code, and this +1/-1 is a place where people often make mistakes. private static int binarySearch(int[] numbers, int numberToFind) { int low = 0, high = numbers.length; while (low + 1 < high) { int middlePosition = (low + high) / 2; int middleNumber = numbers[middlePosition]; if (numberToFind < middleNumber) { high = middlePosition; } else { low = middlePosition; } } if (low < numbers.length && numberToFind == numbers[low]) { return low; } else { return -1; } }
@noobster9212
@noobster9212 Жыл бұрын
very thoughtful idea
@gnair9064
@gnair9064 Жыл бұрын
Hey please don't stop uploading videos you are gret
@programmingwithnurulhuda
@programmingwithnurulhuda Жыл бұрын
It's always good to learn something.
@davidpokol
@davidpokol Жыл бұрын
Great vid John, but here is a little thing you didn't mention about the built-in binary search method: If the number that we looking for is not in the array, the built-in method returns -(insertion point). So for example, if the array contains the following values {1, 2, 4, 5, 7, 9, 11}, and we would like to find 8, it would print -6.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Nice! Didn't realize that about the built in one, that's a nice feature
@reapxiety
@reapxiety 6 ай бұрын
John! I love your vids man, Could you do a Linear Search algorithm? I'm honestly having struggles with that algorithm, very much appreciate it
@fadhlifirdaussulaiman1463
@fadhlifirdaussulaiman1463 3 ай бұрын
Your DSA lectures are making me pass my IVs, damn it I'll repay you one day!!
@ManishYadav-yp2mi
@ManishYadav-yp2mi Жыл бұрын
Your videos are really helpful and good for students like me. If only you can start a series of leetcode solving regularly that would be game changer for us. Whether you upload something or not try to upload problem solving question. thank you
@beachbuggyracing9305
@beachbuggyracing9305 Жыл бұрын
Great sir...
@codeZarathustra
@codeZarathustra Жыл бұрын
Thanks Jhon!
@hemobhai1
@hemobhai1 Жыл бұрын
Thank You Sir
@da_nightcore
@da_nightcore Жыл бұрын
yeah man do more prob solving stuff ,really need them in java
@omparghale
@omparghale 10 ай бұрын
Hey john,which color scheme and theme do you use in your intellij ide?
@user-wg5rd6yz7e
@user-wg5rd6yz7e Жыл бұрын
You`re carrying my grade, I love u
@prasannsurya9415
@prasannsurya9415 Жыл бұрын
Hey john i have a doubt in java, what is the difference between object and instance , please could you make a brief video of that it will very useful to all , and make more understanding of the fundamentals in java
@kieranteets527
@kieranteets527 Жыл бұрын
I love your videos but i was wondering what editor are your using? Keep up the awesome videos!!
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Thanks! I use DaVinci Resolve to edit my videos, it's free and offers everything I need.
@ciccioruccella2248
@ciccioruccella2248 Жыл бұрын
Jhon why dont you start a tutorial about Spring? Thanks to you I learned Java and now I am having some problem with spring without your video! 😁
@newtonnath74
@newtonnath74 Жыл бұрын
Thanks so much. It really helps. Can you please upload a video explaining "Static" keyword? Thanks again!
@denisdominguez7287
@denisdominguez7287 Жыл бұрын
Hi John, great video. But here is a small correction. The result of looking for the number 8 should have been -6. Because binarySearch returns the index where the missing number should be -1 (-(insertion point) - 1). But for an exercise is really cool. Thanks for your time 🙂
@ManosSef
@ManosSef 8 ай бұрын
This is not a correction, it's a different way of doing it. Java's built-in library does it this way, John does it by always returning -1 when not found. Depends on if you actually want to know where the missing element would be though.
@vidyasagar5661
@vidyasagar5661 Жыл бұрын
Hii John Thankyou soo much for all your efforts, if possible can you start making videos on java8 features mostly on stream and its supporting methods like we have many in this streams i,e distinct,averaging int,groupingby,mappingby, etc Thanks in advance
@user-db1im7qm1v
@user-db1im7qm1v 6 ай бұрын
its great video
@djouudjou
@djouudjou 7 ай бұрын
can we do the same but without hard coding the values ? like ask the user to enter all the vales and the target value ?
@AlisonAcostachinchilla18
@AlisonAcostachinchilla18 Ай бұрын
Thanks for the content. But why did you write the binarySearch method as private: "private static int binarySearch" ?
@user-bi9ip5hv3l
@user-bi9ip5hv3l Жыл бұрын
Thnx for the wonderful tutorial and keep up the good work => Btw you look like Mark Strong/ Jhonny Sins 🙂
@ritampramanik1
@ritampramanik1 Ай бұрын
Professor your explanation is genius. Can you help me in an additional part, like if I want to print "Sorry we cannot find the number" instead of -1 what are the changes can we make to modify this code? THANK YOU in advance.
@teo_ke
@teo_ke Жыл бұрын
could you make video about static in class. how it works and where we should use it in
@hackwithharsha
@hackwithharsha 11 ай бұрын
00:07:21 Thank You, Any reason to declare private method as static ?
@user-hc2en1wl4l
@user-hc2en1wl4l Жыл бұрын
hello sir, again with another wonderful video , i would like to ask you if you can make a video about Dependency Injection in java
@TheGamer720x
@TheGamer720x Жыл бұрын
Hi John, I'm curious to know for the experience you have in the software industry, what were the concepts in Java that were crucial in any scenario apart from basic control structures? Any design patterns/frameworks? Any concepts like Inheritance/ Overloading / Overriding etc? Thanks.
@atrivyas8512
@atrivyas8512 Жыл бұрын
all of them are equally important
@trup10ka
@trup10ka Жыл бұрын
Hello, this video was again, awsome, you though me so much during year 2022. I do have a request. Could you make a video about How to use Java with server requests and some things aroud this topic (URL's or something; I'm not really educated in this so please forgive me if I described it badly 😀)
@ahmedhakeem8183
@ahmedhakeem8183 Жыл бұрын
That is great , can you make future vedios like this for other search and sort algorithms and it will be great to explain cone 🥰
@CodingWithJohn
@CodingWithJohn Жыл бұрын
I have a bunch of sorting algorithm videos already, so check them out! Any particular sort or search algorithm I haven't covered you'd like to see?
@programmingwithnurulhuda
@programmingwithnurulhuda Жыл бұрын
@@CodingWithJohn It's always good to learn something.
@csistheonlychoice8256
@csistheonlychoice8256 7 ай бұрын
can you make a video about time complexity of algorithms and Big O, Big Ω etc, notations please??
@kshitijofthejune
@kshitijofthejune Жыл бұрын
Implement red black tree in java.. Using enums
@clarence9527
@clarence9527 Жыл бұрын
hi, john, can you make a episode about the backslash usage in java regex please? such as the "\\\\" impies the "\" in java. it is tricky to understand.
@marknebadon8709
@marknebadon8709 Жыл бұрын
Just one question, from what I can see, is that we get a single number in the middle range when they are an odd set of numbers, so I was wondering what happens if we have 20 inputs in the array, which equals to 20 -1 / 2 in terms of index. What is the number evaluated? help please
@user-kr8uu3bm4k
@user-kr8uu3bm4k Жыл бұрын
John , you are the best programmer-blogger I ever seen. Ukraine is watching you right now 🇺🇦❤️
@eizwaneiz
@eizwaneiz 5 ай бұрын
you know how good your video is? when a 17 minutes video felt tile 5 minutes.
@ngndnd
@ngndnd Жыл бұрын
woah wtf this was posted at the perfect time. I searched this up thinking it was one of your older videos lmao
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Nice! I stole the thumbnail pic from an older video (forgot to take a new one...) so maybe that thre you off
@Avarn388
@Avarn388 Жыл бұрын
Is a good way to think of Binary Search is that if you have a physical dictionary, you’re starting at the middle and going left or right in sections as opposed to starting from the beginning or end of a dictionary? Correct me if I am wrong.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
That's a great way to think about it!
@eugenesmith9940
@eugenesmith9940 10 ай бұрын
I've seen in some binary search realizations that formula to calculate middle pointer looks like that: low + (high - low) / 2. Why is that? Also, inside Arrays class this part of binary search looks like: (high - low) /2 >>> 1. How to read such code? What >>> 1 does in this case?
@girijashankarn
@girijashankarn 8 ай бұрын
Sane question…. Did you get any answer on low+(high-low)/2?
@MaxBondarenko
@MaxBondarenko Жыл бұрын
Does it make sense to use it for Strings array?
@ganastars7402
@ganastars7402 Жыл бұрын
Could you please send me a link for complete course for learning Java for biggner for yourself
@osmanozturk5891
@osmanozturk5891 Жыл бұрын
Thanks John . i have a question if our array was int[] ={1,2,4,5,7,9,11,12} What search algorithm would we use? (fast)
@ManosSef
@ManosSef Жыл бұрын
It doesn't matter what the array is, binary search does the job.
@TheUp001
@TheUp001 Жыл бұрын
john can you make a video on the tree ??😇
@artaxerxes360
@artaxerxes360 Жыл бұрын
Sir please do a video on apache maven
@TheUp001
@TheUp001 Жыл бұрын
you are hero
@pzmt8051
@pzmt8051 Жыл бұрын
Is it possible to run java on colab?
@findlestick
@findlestick Жыл бұрын
Can you do a video about how ChatGPT is changing the coding scene, and its potential consequences?
@kiteSven
@kiteSven Жыл бұрын
Hello. I'm new on this channel. I have an off topic question: Is it ok to commit on using IntelliJ,now that I personally like it more than eclipse? TLDR: I'm not yet a good developer. I'm not yet very confident on my skills. I once had a very skilled teammate who permanently uses eclipse whatever team or company he goes. I thought I should try to do that too: To be consistent on a tool and master it. Since I think that eclipse might be the most popular IDE for java, I should try to stick with it. But now I encountered IntelliJ. For som reason I just learn and adopt quicker now. I also like it's default UI color. And I think it's easier to setup projects here. I think it's more user friendly to beginners or not so good developers like me. I like IntelliJ now but what if in the future, I encounter another team that mainly uses eclipse?
Quicksort Sort Algorithm in Java - Full Tutorial With Source
24:58
Coding with John
Рет қаралды 227 М.
Learn Binary Search in 10 minutes 🪓
10:04
Bro Code
Рет қаралды 98 М.
The most impenetrable game in the world🐶?
00:13
LOL
Рет қаралды 16 МЛН
Trágico final :(
01:00
Juan De Dios Pantoja
Рет қаралды 33 МЛН
OMG 😨 Era o tênis dela 🤬
00:19
Polar em português
Рет қаралды 9 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 585 М.
Learn Selection Sort in 8 minutes 🔦
8:21
Bro Code
Рет қаралды 193 М.
Recursion in Java Full Tutorial - How to Create Recursive Methods
11:11
Coding with John
Рет қаралды 231 М.
Binary Search Tree in Java - 1 : Create Binary Search Tree
14:42
Coding Simplified
Рет қаралды 159 М.
ArrayList in Java Tutorial #36
5:50
Alex Lee
Рет қаралды 515 М.
Learn Insertion Sort in 7 minutes 🧩
7:05
Bro Code
Рет қаралды 174 М.
Selection Sort Theory in Java | DSA
7:00
Telusko
Рет қаралды 11 М.
Learn Bubble Sort in 7 minutes 🤿
7:44
Bro Code
Рет қаралды 206 М.