Тёмный

Learn Binary Search in 10 minutes 🪓 

Bro Code
Подписаться 2,2 млн
Просмотров 114 тыс.
50% 1

binary search algorithm tutorial example explained
#binary #search #algorithm
// binary search = Search algorithm that finds the position
// of a target value within a sorted array.
// Half of the array is eliminated during each "step"
music credits 🎼 :
===========================================================
Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
Free Download / Stream: bit.ly/2JnDfCE
Music promoted by Audio Library • Up In My Jam (All Of A...
===========================================================

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

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 144   
@BroCodez
@BroCodez 3 года назад
import java.util.Arrays; public class Main{ // binary search = Search algorithm that finds the position // of a target value within a sorted array. // Half of the array is eliminated during each "step" public static void main(String[] args) { int array[] = new int[1000000]; int target = 777777; for(int i = 0; i < array.length; i++) { array[i] = i; } //int index = Arrays.binarySearch(array, target); int index = binarySearch(array, target); if(index == -1) { System.out.println(target + " not found"); } else { System.out.println("Element found at: " + index); } } private static int binarySearch(int[] array, int target) { int low = 0; int high = array.length - 1; while(low target) high = middle - 1; else return middle; //target found } return -1; } }
@thamendranreddy959
@thamendranreddy959 3 года назад
Could you please make an in depth video on Binary Search Trees including how to balance them ?
@xaliqesgerzade6526
@xaliqesgerzade6526 Год назад
Feridusssssssssss
@MyQlus-iswatching
@MyQlus-iswatching 8 месяцев назад
thanks heres a comment cause you asked
@heayyyyyyy11
@heayyyyyyy11 3 года назад
Had a task with binary search. Didn't understand -> open Bro Code Data Structures and Algorithms Playlist -> Found Binary Search -> Understood :D
@habboholoful
@habboholoful 3 года назад
I hope that you can do some tutorials about every data Structure or techniques... I love they way you teach
@mypie-5952
@mypie-5952 11 месяцев назад
@xavier from alternate universe be like
@sathishn02
@sathishn02 3 года назад
Bro instagram id plezzz
@nikaarudashvili1353
@nikaarudashvili1353 3 года назад
You are underrated af
@niksonney4462
@niksonney4462 3 года назад
For Sure
@aer0449
@aer0449 3 года назад
@@niksonney4462 Yeah man I did ask my friends to subscribe him :)
@luismatos684
@luismatos684 Год назад
I cannot believe how simple you made this. Every other video I saw eventually caused confusion. You clearly stated the concept first, where every thing that followed fell into place. This has been my experience in your other videos learning C#, and Python programming languages. God Bless You.
@AbhijeetKumar-cm3jh
@AbhijeetKumar-cm3jh 3 года назад
Face reveal on 100k ?
@prodiptamondal1758
@prodiptamondal1758 3 года назад
Please also solve some leetcode problems
@JohnWickXD
@JohnWickXD 3 года назад
So underrated....Bro keep goin❤... I know u hate it but waiting for ur OP android app development lol
@quinnmurphy964
@quinnmurphy964 Год назад
U are a god. I have used your tutorials since I started programming in april 2022... You have no idea how much you have helped me out man!! all for free!!!!
@passportbro904
@passportbro904 2 месяца назад
please stop calling random people god as our real god will ask you why u said that when u meet him. just saying, theres only 1, but bro is gods homie tho
@ethanalkout949
@ethanalkout949 3 года назад
am officially done with "programming" but I will keep my subscription ❤
@mykyta1235
@mykyta1235 Год назад
You are pathetic.
@dazzledave
@dazzledave 3 месяца назад
How are u "done" lol
@Thats_Handle0
@Thats_Handle0 2 месяца назад
​@@dazzledaveWell i guess he quiet or something
@aer0449
@aer0449 3 года назад
Thank you so much for making such a great content
@monemperor1559
@monemperor1559 3 года назад
this was actually really nice. itd be nice if you had even more stuff on datastructures and algos so i can become an algo chad
@baubaudinamo
@baubaudinamo 3 года назад
go super Bro!
@sanjays9082
@sanjays9082 3 года назад
Hey bro, please make video of react js or angular 🤩
@rewardx
@rewardx 3 года назад
gucci gang gucci gang gucci gang gucci gang gucci gang gucci gang
@paultvshow
@paultvshow 6 месяцев назад
Hey, bro. I just wanted to let you know that when it comes to teaching and explaining code, you are the best of this world. I am not exaggerating; I have watched hundreds of channels, and taken tens of paid online courses, no one is as nearly as good as you.
@freakintruder
@freakintruder Год назад
Your way of teaching is just fantastic bro🤩. You are the best. Love from India❤
@sriharivernekar2255
@sriharivernekar2255 Год назад
Amazing video bro, Thank You so much.
@eugene-white-shark
@eugene-white-shark 3 года назад
Nice tutorial
@GamingPro-xn4hy
@GamingPro-xn4hy Год назад
Help the yt algorithm
@creampielover69
@creampielover69 3 года назад
We had to implement a binary search algorythm in the past semester in practical informatics. It wasn't really hard but I still ask myself if it is really used in the world or was it just a simple mind exercise to prep us for the whole algorythms and data structures shtick? I mean the code looks and works so simple, it just seems... I don't know, too simple.
@BroCodez
@BroCodez 3 года назад
One example where I find it helpful is when searching through users in alphabetical order. There's no need to iterate through all the users to find one you're looking for
@Sammysapphira
@Sammysapphira Год назад
Binary search is one of the easiest and most efficient searches for anything that is in ascending or descending order.
@strex2062
@strex2062 3 года назад
6:13 Why not (high+low)/2 so average of two elements is the middle? Im not saying your is wrong, just it feels weird.
@BroCodez
@BroCodez 3 года назад
I suppose that would work too! The book I read used: low + (high - low)/2 I thought there might be something I might be missing if I changed formulas
@bsagar5306
@bsagar5306 3 года назад
@@BroCodez No it won't work and the value of middle will repeat itself again and again...
@bsagar5306
@bsagar5306 3 года назад
It will stuck in a constant loop
@sarabjeetsinghhora7751
@sarabjeetsinghhora7751 2 года назад
Because (high + low) / 2 has a possibility of exceeding the Integer Range. i.e: (int + int)/2 // this could exceed Integer range hence breaking your code. (int) + (int- int)/2 The possibility of exceeding Integer range is minimum.
@vijayanks1714
@vijayanks1714 2 года назад
yeah middle = (low+high)/2; is work, replace the formula that bro use. You see the same result!!! happy coding💲💲
@vklmao8677
@vklmao8677 3 года назад
good job bro....!
@ganymedeshortride
@ganymedeshortride 3 года назад
Better than any movie.
@mykyta1235
@mykyta1235 Год назад
Jesus Christ, how such a great content is such an underrated... Horrifically underrated. P. S. : this English... I'VE BEEN WAITING FOR THE NON INDIAN CODE CONTENT FOR A YEARS...
@sergeistankovski7250
@sergeistankovski7250 3 года назад
You are the best!💻
@worldwide6626
@worldwide6626 3 года назад
Underrated. Could you make one on Ternary Search Tree, Hashing (like double hashing), string search,MSD radix sort, RB trees. in your playlist. Would appreciate it
@worldwide6626
@worldwide6626 3 года назад
and maybe heaps
@wolanus
@wolanus 3 года назад
Great video, thanks bro.
@projectspace786
@projectspace786 Год назад
Awesome!
@jevardspproxyacct6832
@jevardspproxyacct6832 2 года назад
Thanks bro *ongoing comment crusade while i cram*
@simplifiable5281
@simplifiable5281 Год назад
well, you're an absolute legend that's all I got to say
@Kwame_Kwao
@Kwame_Kwao 3 года назад
Bro you are genus !😍😍😍
@theuberman7170
@theuberman7170 3 года назад
Thank you so much Lord Bro Code. I was able to finish my Java final semester project thanks to you sir.
@doaa_alshawwa
@doaa_alshawwa Год назад
help me ,help you
@RinInABin
@RinInABin 3 года назад
commenting for the algorithm love your stuff my guy 👍
@ixer6661
@ixer6661 Год назад
is this method usable to unsorted array?
@bingusiswatching6335
@bingusiswatching6335 5 месяцев назад
No
@mohitjain957
@mohitjain957 2 года назад
thanku sir
@dcentdevelopers3435
@dcentdevelopers3435 3 года назад
You Know One Thing!..... You Are My Bro.....
@carlosramon4981
@carlosramon4981 2 года назад
A hi from "Brazil' Bro, code! You are the guy.
@germanhoyos4422
@germanhoyos4422 2 года назад
... can you literally just teach me everything, math / science / life..... lol you vids are so clear and easy to understand
@AnaGuerra03
@AnaGuerra03 Год назад
thank you. Your video helped a lot.
@mikeafter5
@mikeafter5 3 года назад
Thanks
@Remolhunter97
@Remolhunter97 2 года назад
You saved the day, AGAIN ! Thanks so much bro, take care of you ! :)
@Yumiesthetic
@Yumiesthetic Год назад
package Java_Programs; import java.util.Arrays; import java.util.Scanner; public class BinarySearch { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the size of the array: "); int size = input.nextInt(); int[] arr = new int[size]; System.out.print("Enter your target. Enter 0 or positive integers only: "); int target = input.nextInt(); for (int i = 0 ; i < arr.length ; i++) arr[i] = i; int index = Arrays.binarySearch(arr, target); if (index == -1) System.out.println(" Using the built-in binary search method in Java, the target " + target + " is not found. "); else System.out.println(" Using the built-in binary search method in Java, the target " + target + " is found. "); int returnValue = binarySearchMethodTwo(arr, target); if (returnValue == -1) System.out.println(" Using a user-created method, the target " + target + " is not found."); else System.out.println(" Using a user-created method, the target " + returnValue + " is found."); } private static int binarySearchMethodTwo(int[] arr, int target) { int min = 0; int max = arr.length - 1; int steps = 1; System.out.println("User-created method:"); while (min target) max = midPosition - 1; else return midPosition; } return -1; }
@josiahmartin6463
@josiahmartin6463 2 года назад
So much knowledge
@ٱسمر
@ٱسمر 3 года назад
thx
@dandantin
@dandantin 2 года назад
Thank you, bro code! Excelent explaining.
@dreamphoenix
@dreamphoenix Год назад
Thank you.
@chadsmith71
@chadsmith71 8 месяцев назад
I love your videos, they are very helpful and easy to grasp. But I must admit my OCD gets triggered when you don't put your else on the same line as the closing curly brace of the respective if... xD
@augischadiegils.5109
@augischadiegils.5109 3 года назад
@xaliqesgerzade6526
@xaliqesgerzade6526 Год назад
Feriduussssssss
@kseniyavolkov6689
@kseniyavolkov6689 3 года назад
thank you!
@saicharan4212
@saicharan4212 3 года назад
👍
@maxhill9037
@maxhill9037 7 месяцев назад
why everyone finds middle with complex formula, instead of (low+high)/2, while both give same result???
@Sub-zero1123
@Sub-zero1123 3 года назад
Thanks bro, this is awesome
@Kerzyist
@Kerzyist 10 месяцев назад
Ehhhh Mazing
@pholoshomothiba3832
@pholoshomothiba3832 Год назад
Great vid
@slade8863
@slade8863 2 года назад
yo, random comment
@DineshKumar71
@DineshKumar71 22 дня назад
why not use low+high/2, in simple it works fine, but low and high values are large, then integers might overflow
@MrLoser-ks2xn
@MrLoser-ks2xn Год назад
Thanks!
@mindlessmeat4055
@mindlessmeat4055 Год назад
Love your video it is really great. How would you do a binary search if the array was filled with like 3 digit hex codes or some string similar to that? Like the first one would be AAA and the second would be AAB. Would I need to convert them to some number?
@adityapratapsingh7016
@adityapratapsingh7016 2 года назад
@anuarcool3275
@anuarcool3275 Год назад
cool
@bawarkhalid2651
@bawarkhalid2651 2 года назад
BEST!
@100sdf9
@100sdf9 2 года назад
sd
@keerthivasanmohan1974
@keerthivasanmohan1974 6 месяцев назад
good explanation but explain the while loop part too and why we are using middle +1 and middle -1 for effective understanding
@hannibalbianchi1466
@hannibalbianchi1466 3 года назад
Thank you, sir 👍👍👍
@prizepig
@prizepig 2 года назад
This example gave me a much better understanding of how searching works.
@redscorpion7000
@redscorpion7000 2 месяца назад
what a legend ,watched his vid 5 days b4 exam and got a 97/100
@mohammad_zrar
@mohammad_zrar 2 года назад
Well done, thank you a lot bro.
@folksypegasus9188
@folksypegasus9188 Год назад
Ha nice 👍🏿
@stephenmirador8549
@stephenmirador8549 Год назад
$ey bro
@mflavia3368
@mflavia3368 3 года назад
Do you think you can help me with my javafx project? I can pay you please! I need to implement a searchbar on a tableview I got from input
@BroCodez
@BroCodez 3 года назад
I would love to help, but I barely have any time with running this channel and my day job :(
@dimitriskarkavelias
@dimitriskarkavelias Год назад
Hey. Does this actually work for the highest value? If target is at position arr.length -1 will it find it? Because i tried implementing it and for that particular case it didn't work (returned -1. I probrably have some mistake though but thought of asking too).
@karamzeitouni7911
@karamzeitouni7911 Год назад
It should work, low should get larger until it equals high (arr.length-1). Once it reaches that, if arr[arr.length-1] ==target, it should return true. Otherwise high will be lower than low and the function returns -1
@sanjana9599
@sanjana9599 3 года назад
this channel should have more than a million subscribers!!!
@TheKr0ckeR
@TheKr0ckeR Год назад
Thanks a lot friend! The first explanation is great! I am normally c# user but can easily follow your tuts since its similar. What i cant understand is how while loops is going to break, for example when start is greater end in that situation.
@rafl277
@rafl277 Год назад
Great explanation, thanks a lot!!
@juanandresstingo
@juanandresstingo 8 месяцев назад
it would be nice a recursive explanation also.
@Ri_sab55
@Ri_sab55 4 месяца назад
Hi bro, I still don't understand why we don't simply calculate middle like this : (high + low ) / 2 , since we are talking about indices than we won't face an overflow issue right ?
@Izzy-tl3gp
@Izzy-tl3gp День назад
i am wondering the same thing!
@fauzanadityaharsya6146
@fauzanadityaharsya6146 9 месяцев назад
Thank you. Such a helpful video
@lukrau15
@lukrau15 4 дня назад
you're the organic chem tutor of coding
@dr.caffeine232
@dr.caffeine232 Месяц назад
You are smoother than Bro Code Liquor
@Yeganeh_ht
@Yeganeh_ht 7 месяцев назад
this was helpful thank you
@ddelorez
@ddelorez 10 месяцев назад
This is essentially how you troubleshoot ground faults in a fire alarm notification circuit - split the circuit in the middle and look for the short to ground on either end (hopefully you don't find a short to ground on both ends).
@tiavanderyacht5702
@tiavanderyacht5702 4 месяца назад
You do an outstanding job of making the content easy to understand. You have helped me get through my class this quarter thank you!
@rayhanrajhendra6128
@rayhanrajhendra6128 9 месяцев назад
it is a good video, nice, i like it papa
@WissemMERRI
@WissemMERRI 9 месяцев назад
Great methodology 🎉 thx
@RamjeUthayakumaar
@RamjeUthayakumaar 8 месяцев назад
Dude is the GOAT fr
@hakikatsingh6254
@hakikatsingh6254 Год назад
bro code is bro god after this
@tsaykostya
@tsaykostya Год назад
Wow nice channel bro❤
@jordanmartin2632
@jordanmartin2632 11 месяцев назад
Here I was over complicating it in my head thank you!
@투오아
@투오아 6 месяцев назад
shout out from South Korea
@blackvampiremovie
@blackvampiremovie 3 месяца назад
thank you so much!
@ntombizakhexego-jimlongo8577
@ntombizakhexego-jimlongo8577 8 дней назад
thank you
@TheEvertonDias
@TheEvertonDias Год назад
Thanks, Bro!
@ashvikvijai8114
@ashvikvijai8114 5 месяцев назад
Thank you!
@eugenezuev7349
@eugenezuev7349 Месяц назад
sweet
@AHorseWithNoName-bs7sm
@AHorseWithNoName-bs7sm 8 месяцев назад
Thank you!
@sujitagrahari1105
@sujitagrahari1105 7 месяцев назад
fellow bro
Далее
Learn Interpolation search in 8 minutes ❓
8:24
Просмотров 41 тыс.
Binary Search in Java - Full Simple Coding Tutorial
17:48
Лайфак года 😂
00:12
Просмотров 103 тыс.
Binary Search Algorithm - Computerphile
18:34
Просмотров 161 тыс.
Learn Quick Sort in 13 minutes ⚡
13:49
Просмотров 345 тыс.
SHA: Secure Hashing Algorithm - Computerphile
10:21
Просмотров 1,2 млн
Learn Binary search trees in 20 minutes 🔍
20:25
Просмотров 162 тыс.
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 377 тыс.
How Binary Search Makes Computers Much, Much Faster
6:51
Bug in Binary Search - Computerphile
11:31
Просмотров 286 тыс.
Learn Merge Sort in 13 minutes 🔪
13:45
Просмотров 304 тыс.
A* (A Star) Search Algorithm - Computerphile
14:04
Просмотров 1,1 млн