Introduction to Binary Search (Data Structures & Algorithms #10)

  Рет қаралды 253,231

CS Dojo

CS Dojo

Күн бұрын

Пікірлер: 279
@CSDojo
@CSDojo 4 жыл бұрын
If you’re already familiar with binary search, I’d recommend the practice problem I introduced at 12:17. It’s a nice problem from my business affiliate algoexpert.io/csdojo - from which you can get a discount with my referral code csdojo.
@Ali-mc4le
@Ali-mc4le 4 жыл бұрын
What is the blackboard app or tool you are using to show code examples? Looks great! I just joined algoexpert because of you :)
@htol78
@htol78 4 жыл бұрын
+1 what software do you use to create presentation? looks pretty good.
@bhagwandas321
@bhagwandas321 4 жыл бұрын
Hello dojo thank you
@ahammedafzal7797
@ahammedafzal7797 4 жыл бұрын
def search(arr, target): l = 0 r = len(arr)-1 while l arr[r] and target < arr[m]: r = m-1 else: l = m+1 return -1 right?
@tylerdurden4169
@tylerdurden4169 4 жыл бұрын
Continue this series of data structures.
@nx8221
@nx8221 4 жыл бұрын
would be great!
@lakshkaushik6366
@lakshkaushik6366 4 жыл бұрын
Check out apni kaksha for ds and algo
@acm1812
@acm1812 4 жыл бұрын
@@lakshkaushik6366 no
@adibattie9619
@adibattie9619 3 жыл бұрын
It's not obvious how much binary search helps until you actually code it and time it yourself. It's actually amazing. Thanks for the informative videos!
@manuelelkess8259
@manuelelkess8259 4 жыл бұрын
This course of data structures and algorithms one of the best on the internet I really hope you continue it to the very end.
@ctcrnitv
@ctcrnitv 4 жыл бұрын
You are such a good teacher. I already knew what binary search was but this was brilliantly explained, probably the clearest explanation I've ever seen.
@prernacore
@prernacore 4 жыл бұрын
please continue this course. it's the best that I have ever stumbled upon. Been watching all the videos since morning and I am so grateful for these , cleared all the doubts and making basics easier and clear. Thank you!
@TheNaderpop
@TheNaderpop 4 жыл бұрын
Man, how do I love your introduction to this series so much , I hope you finish this series as soon as possible.
@shokhrukhbekyursunjonov6203
@shokhrukhbekyursunjonov6203 4 жыл бұрын
That's so cool, learned a lot. I, myself, for example solved it like following: def search(arr,target): if target in arr: for i in arr: if arr[i]==target: return i print(search([1,2,3,11],11)) output: 3
@asdfractal8115
@asdfractal8115 4 жыл бұрын
The way you explain the process of thinking about the problem is really good. While you are explaining the problem I can already imagine the code required to solve it. Your videos have helped me a lot to conceptualize solutions to my problems.. so thank you very much!
@dreamofmirrorsguy7043
@dreamofmirrorsguy7043 2 жыл бұрын
You are insanely the best pragmatic youtuber and teacher I've watched so far. Thank you very much for your content!
@samuraijack5919
@samuraijack5919 4 жыл бұрын
I'm not gonna lie, it is still hard to wrap my head around some of this stuff like time complexity and Big O. Thank you for all that you do!
@sashamuller9743
@sashamuller9743 4 жыл бұрын
same bro same
@Veigaburame
@Veigaburame 4 жыл бұрын
the way you seperate exercise into 10-15 minutes is pretty handy. I could spend time watching your video while having lunch. Love to see these kind of videos uploaded on KZbin. Thanks Dojo hehee
@dailycodingproblem8346
@dailycodingproblem8346 4 жыл бұрын
I’m 4 days away from turning 93 and CS Dojo inspired me to create my own tutorials. Thanks, CS Dojo!
@stevepriest5113
@stevepriest5113 4 жыл бұрын
Happy birthday
@shubhamiot326
@shubhamiot326 4 жыл бұрын
@@stevepriest5113 I advance
@Name-mi7bx
@Name-mi7bx 4 жыл бұрын
Fake, not the first time a simp Commented the same shit.
@Importunity
@Importunity 4 жыл бұрын
you did not sound like you were turning 93 in your video bruh
@DjLeonSKennedy
@DjLeonSKennedy 4 жыл бұрын
5 years i couldn't understand about complexity until now! thanks
@cpbeatzx2263
@cpbeatzx2263 Жыл бұрын
This is no joke one of the best videos ive watched, I do not comment on youtube videos, but this deserves one. Thank you
@tylerxiao2656
@tylerxiao2656 4 жыл бұрын
My idea for shifted binary search: Copy the array once, so that an array like [3,1,2] becomes [3,1,2,3,1,2]. Next, we compute the maximum and minimum values of our original array, which are 3 and 1, respectively. Then, we run 2 pointers to find the indices of the range between the minimum and maximum, which in our example the indices are 1 and 3, and we binary search through those values.
@tylerxiao2656
@tylerxiao2656 4 жыл бұрын
Never mind, I watched the Errichto video on this. Rip I got this wrong
@rajibdpi
@rajibdpi 4 жыл бұрын
Thank you so much for this great opportunity to Learn Dara structures and Algorithm with you.
@williambasquez7607
@williambasquez7607 4 жыл бұрын
Back at it again with the good stuff 👨🏻‍💻💻
@mansmor7211
@mansmor7211 2 жыл бұрын
I can't not to like your videos, using technology and explaining in a simplest way makes it easy to understand even very difficult subjects.
@huckleberryfinn8795
@huckleberryfinn8795 Жыл бұрын
The best programming lessons on KZbin!!
@rakotonirinaolvanotjeancla1990
@rakotonirinaolvanotjeancla1990 4 жыл бұрын
i am very very very happy to see you again. you are the best for explaination
@kuberchaurasiya
@kuberchaurasiya 4 жыл бұрын
Thanks. The sorted rotated array problem is very interesting
@SarangDhanurdhari
@SarangDhanurdhari 4 жыл бұрын
Thanks a lot dojo. Please keep continuing this series.
@mattoattacko
@mattoattacko 4 жыл бұрын
Heck yeah! You totally came through. Much appreciated mate!
@nagendradevara1
@nagendradevara1 3 жыл бұрын
I have tried the python example in JavaScript function binarySearch(arr, target) { let left = 0; let right = arr.length - 1; arr = arr.sort((a, b) => a - b) while (left
@neevetiasli
@neevetiasli 11 ай бұрын
For the first time ever i really understood
@lucyledezma709
@lucyledezma709 4 жыл бұрын
Hello CS Dojo!!!. I am so happy for the new video!!!
@homealone8946
@homealone8946 4 жыл бұрын
Dojo, man this was a crystalclear explanation. Thank You very much.
@proggaparomita281
@proggaparomita281 Жыл бұрын
KZbinrs I owe my whole degree: CS Dojo, Code with Harry and Organic Chemistry Tutor .
@BoopeaTech
@BoopeaTech Жыл бұрын
You're great. The explanations are really broken down. Thank you👍
@hmchemistry7883
@hmchemistry7883 4 жыл бұрын
Thanks CS Dojo. The practice problem was fun! public static int ShiftedBinarySearch(int[] array, int target){ int l=0, r=array.length-1, mid=0; while(larray[r]){ mid=(l+r)/2; if(array[mid]==target) return mid; else if(array[mid]array[mid] && target=array[l] && target
@sase1017
@sase1017 3 жыл бұрын
I think there is a mistake with last part of pointer movement when target = 12, when left pointer will be equal to right pointer, we will exit the while loop(Left = right) with return -1, left and right pointers will not pass over each other.
@frixaco
@frixaco 4 жыл бұрын
Reaaly great explanation! Thank you very much and continue these series!
@lysekthe
@lysekthe 4 жыл бұрын
I applied this algorithm in my work, thank you!!!
@niquebon
@niquebon 3 жыл бұрын
THANK YOU! for saving me always. Your tutorials are easy to understand compared to others. Great teacher!
@jahanvi9429
@jahanvi9429 3 жыл бұрын
You are my saviour!!!!! thank you so much. i was having so much trouble with this
@DatascienceConcepts
@DatascienceConcepts 4 жыл бұрын
Nice explanation! Searching Algorithms are super interesting and important :)
@arjunthecoder
@arjunthecoder 4 жыл бұрын
Love this video. Great Refresher!!!
@KevinGarcia-ws1kt
@KevinGarcia-ws1kt Жыл бұрын
Thank you for this video. That was a really clear explanation
@TheMatias2
@TheMatias2 3 жыл бұрын
Best explanation I found on YT! thanks!
@erza4876
@erza4876 4 жыл бұрын
It would be great if you can share some experience in dealing with conditions in binary search templates, e.g., left < right or left
@feding3328
@feding3328 3 жыл бұрын
Thank you so much CS Dojo
@shubhamiot326
@shubhamiot326 4 жыл бұрын
Keep on making videos... Salute from india
@kumaracademy7555
@kumaracademy7555 4 жыл бұрын
I am your student from India❤
@pranavm2539
@pranavm2539 4 жыл бұрын
Me too
@mokshanirugutti
@mokshanirugutti 4 жыл бұрын
Same
@vivekpatel5555
@vivekpatel5555 4 жыл бұрын
Me too
@GhostVaibhav
@GhostVaibhav 4 жыл бұрын
Bro, increase the frequency of ur videos!! It will be of great help to everybody..!
@iig1017
@iig1017 4 жыл бұрын
Great video with a lot of information. Thank you for all!
@fazeefathima1041
@fazeefathima1041 4 жыл бұрын
Thanku so much sir, I am your subscriber from INDIA✌️😊
@plor1261
@plor1261 4 жыл бұрын
Great teaching and it was very fun to learn!
@sriramkasu7511
@sriramkasu7511 4 жыл бұрын
Finally he is back with this series
@maddada
@maddada 4 жыл бұрын
Very clear explanation, thank you very much! Please keep them coming
@HShravzP
@HShravzP 4 жыл бұрын
This is so helpful. Thankyou and please continue this series :)
@nandhakumaranm6006
@nandhakumaranm6006 4 жыл бұрын
Please continue the python series. Really waiting for more videos. I have started learning by watching your videos plz do teach more
@maulanaputro1966
@maulanaputro1966 4 жыл бұрын
Really looking forward to your next videos in this series!
@samsungfateh8686
@samsungfateh8686 4 жыл бұрын
Thank you for your very useful tutorial videos My English is not very good. Thank you for always subtitling the videos I wish you good health and increasing success from God Almighty
@saiint9991
@saiint9991 4 жыл бұрын
Good stuff❤... Continue all concepts related to data structures.
@madhavgoyal1068
@madhavgoyal1068 4 жыл бұрын
YK! Kindly do complete this Playlist as I don't wanna wander about different places after already starting your Playlist. Thanks. ~ FAN
@iamakifislam
@iamakifislam 4 жыл бұрын
Thanks. I was waiting for this video ! Please continue DS and Algo Series
@anuragd398
@anuragd398 4 жыл бұрын
Back at it again with the good stuff YK
@diveshkosuri5594
@diveshkosuri5594 3 жыл бұрын
You just made it so simple! Thanks
@mdsaifalam9823
@mdsaifalam9823 4 жыл бұрын
Hello Dojo I am your student from India.💕💕
@surajk6550
@surajk6550 4 жыл бұрын
Where from India brother
@Devakvp
@Devakvp 2 жыл бұрын
Clean explanation! Thank you so much!
@masqueradeee
@masqueradeee 4 жыл бұрын
Thank you so much great explanation 👍 pls upload more videos on Data structures.
@shivamgahoi
@shivamgahoi 3 жыл бұрын
I believe when target=12 eventually L=value 13 or index 7 and right = value 11 or index 6... So this is a mistake in video @12:05 ... Please correct if possible... By the way awesome content... Love from India ❤️😍
@kR0N0Z618
@kR0N0Z618 4 жыл бұрын
these videos are a godsend. very well articulated! keep it up! i look forward to more videos in the series!
@yathirajraghavendra1674
@yathirajraghavendra1674 4 жыл бұрын
Please do continue this DSA course.. I am your student from India. . You are my fav youtuber
@nareshreddy3344
@nareshreddy3344 3 жыл бұрын
Please continue this series
@IkramIkram-gm3zg
@IkramIkram-gm3zg 3 жыл бұрын
do u please know how can we solve the problem given at the end ?
@fayazansari2827
@fayazansari2827 4 жыл бұрын
Next Upload a video about different types of algorithm such as dynamic, greedy etc. Please 🙏
@Raj_Tanvar
@Raj_Tanvar 4 жыл бұрын
Thanks a lot for such a great video... Well explained easily understandable
@vulnerablegrowth3774
@vulnerablegrowth3774 3 жыл бұрын
Ok, so binary search only works if the list is sorted or sorted+shift, correct? But, I then I have a question. Why not check if the target is more or less than the range of values before starting the loop? We just assume that’s less likely to happen so we’d rather go straight to checking targets which can be found first? As in, “hey, if you sent us a target that doesn’t fit in the list, you’re gonna have to wait.”
@dexteritylord1725
@dexteritylord1725 4 жыл бұрын
Thanks a lot for your effort. please make a tutorial on Merge sort algorithm + quick sort algorithm
@JMBTV1988
@JMBTV1988 4 жыл бұрын
Wow.. thank you for this tutorial. I badly needed this one
@udoyonb274
@udoyonb274 4 жыл бұрын
This is brilliant! Thank you so much!
@wisdomovermoney3394
@wisdomovermoney3394 3 жыл бұрын
You made it so simple.
@codingbro3499
@codingbro3499 4 жыл бұрын
Dojo you are my programming inspiration
@akashk__6894
@akashk__6894 4 жыл бұрын
Your videos are really helpful ! continue your good work .
@parteeks9012
@parteeks9012 4 жыл бұрын
class Solution { public: int search(int A[], int n, int target) { int lo=0,hi=n-1; // find the index of the smallest value using binary search. // Loop will terminate since mid < hi, and lo or hi will shrink by at least 1. // Proof by contradiction that mid < hi: if mid==hi, then lo==hi and loop would have been terminated. while(loA[hi]) lo=mid+1; else hi=mid; } // lo==hi is the index of the smallest value and also the number of places rotated. int rot=lo; lo=0;hi=n-1; // The usual binary search and accounting for rotation. while(lo
@hakanaki
@hakanaki 2 жыл бұрын
do you have a tutoral on Hash maps, Stacks/Queues/Heap/Priority Queue ?
@trongdoan817
@trongdoan817 3 жыл бұрын
super clear instruction. Thank you.
@setarehsh3749
@setarehsh3749 4 жыл бұрын
KZbin... It's not giving me notifications even though I put it to all.. 😐 Thank you for all the free info!
@sidheshwartiwari9834
@sidheshwartiwari9834 4 жыл бұрын
And I am getting notifications from channels I never even subscribed to ,let alone clicking the bell icon. What a tragedy🙄
@setarehsh3749
@setarehsh3749 4 жыл бұрын
@@sidheshwartiwari9834 LoL
@aznguyener
@aznguyener 3 жыл бұрын
nice series! please continue
@p_square
@p_square 4 жыл бұрын
Legend back again!!
@nguyenlethuong186
@nguyenlethuong186 4 жыл бұрын
I like your explanations and I'd love if u make more videos like this
@SourLemonFan
@SourLemonFan 4 жыл бұрын
Thanks for your help! These videos are amazing!
@nationhlohlomi9333
@nationhlohlomi9333 2 жыл бұрын
Great video as always
@shreya1201
@shreya1201 3 жыл бұрын
such a good explanation!
@eduardomartinez6521
@eduardomartinez6521 4 жыл бұрын
Thanks for the lesson !. Do you have any video or resource where you list or describe the personal projects you did before you applied for Google?
@anamika5984
@anamika5984 4 жыл бұрын
Bro please continue this stuff🙏
@unknownunknown8699
@unknownunknown8699 2 жыл бұрын
why u gotta check n/2 elements its a computer always starts from 0 to n numbers search(array, the value u r searching for) so where did the n/2 come from ? is it something i should just memorize ?
@porobertdev
@porobertdev 5 ай бұрын
I suppose you're talking about Time Complexity. He broke down the number of steps an algorithm has to take when searching within 40 elements, showing how we get to the O(log N) aka logarithmic time complexity. Since this algorithm halves an array until the element is found or halved's length is 1, that means the first halved array would be n/2, where n is the length of the array. If the element is not found, then n/4 if we use the main array's length, otherwise we could say n/2 of the halved array. I don't think it's important to memorize this, but you should remember that whenever an algorithm keeps halving an array by looping or using recursion, then the time complexity should be O(log N). You can test that by doubling up the size of the input, and see the difference between the number of steps. As per its definition, O(log N) states that the number of steps grows by 1 when the input size is doubled.
@elmehdimedrani1240
@elmehdimedrani1240 4 жыл бұрын
Thank you for sharing this content!
@programmingwithjackchew903
@programmingwithjackchew903 4 жыл бұрын
can I know for the binary search only can suitable for ascending order and not suitable for the elements in the list that Is not order right for example [-2,3,1,8,6]
@waisetsubunsho7934
@waisetsubunsho7934 Жыл бұрын
Why is there no condition for when target is < left or > right? Or just plain =left or =right?
@valacascrane9156
@valacascrane9156 4 жыл бұрын
You are quite an inspiring guy. Keep on!
@spacewitch9987
@spacewitch9987 3 жыл бұрын
your videos are so helpful, dude. tysm! ;u;
@ahammedafzal7797
@ahammedafzal7797 4 жыл бұрын
Will you teach it completely? Can someone familiar with python understand this course(knows only little about c)?
@picumtg5631
@picumtg5631 4 жыл бұрын
yeah ofc. His pseudocode is basically python. The only difference between python and c on the complexity of his program is that there are ; at the end of each command(where in python there is nothing behind it) and some random brackets like ()[]{}after if and while and for loops. If you just pretend they are no brackeys there there you are fine
@haddonjames5829
@haddonjames5829 3 жыл бұрын
great explanation
@ameiragha2419
@ameiragha2419 4 жыл бұрын
I am really appreciate your effort CS Dojo. if it’s possible can you make next episode about hash table? Peace.
@mnt86
@mnt86 2 жыл бұрын
9:23 But doesn't array.length make the code go through each element in the array in the background to count how many elements are there in the array? If so, then what's the point of using binary search instead of linear since it'll iterate anyway?
@champagnepop
@champagnepop 4 жыл бұрын
Can I just sort the unsorted array that was given in the problem? Then apply with the given solution?
@saksh.j
@saksh.j 4 жыл бұрын
Hey dojo. I've recently started to get intrest in computers and coding - I'm an extreme beginner. So which video of yours i should watch or what basics should I start or begin with. Thank you
@Raj_Tanvar
@Raj_Tanvar 4 жыл бұрын
Bro, Please continue this series on data structures and algorithms & please keep continue with python code as wll
Introduction to Trees (Data Structures & Algorithms #9)
10:30
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 163 М.
Lecture 1: Algorithmic Thinking, Peak Finding
53:22
MIT OpenCourseWare
Рет қаралды 6 МЛН
How Binary Search Makes Computers Much, Much Faster
6:51
Tom Scott
Рет қаралды 1,4 МЛН
Learn Binary Search in 10 minutes 🪓
10:04
Bro Code
Рет қаралды 124 М.
Binary Tree Algorithms for Technical Interviews - Full Course
1:48:53
freeCodeCamp.org
Рет қаралды 734 М.
12. Searching and Sorting
48:32
MIT OpenCourseWare
Рет қаралды 179 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН