I cant put into words how helpful this was. Keep it up!!
@mycodeschool11 жыл бұрын
You're welcome Aaron !!
@jeanphilius75007 жыл бұрын
Great explanation Animesh! If anyone is confused by why Animesh switched to formula mid = (high - low)/2 + low 1:04 Here's how I was able to wrap my head around it. lets PRETEND anything over 10 causes an OverFlowException. We will set low and high arbitrarily to 4 and 8 respectively (e.g., low = 4, high = 8). Therefore, in our contrived example, if we sum low + high we get an OverFlowException, because 4 + 8 = 12 which is greater than 10 (the highest number we can handle before overflowing). This is why using formula mid = (high + low) /2 breaks down. A more robust formula would be mid = (high - low)/2 + low .... And if we plug in values from our contrived example to calculate mid = (high-low)/2 + low = (8-4)/2 + 4 = 6 we see that it gives us the same answer as mid= (high + low)/2 = (8+4)/2 = 6 but without causing an OverFlowException!
@spacetime_wanderer6 жыл бұрын
Good example. I would initially prefer 'mid = floor((high/2) + (low/2));' at least till I remember low + (high-low)/2. The disadvantage in my way I feel is division is slightly more costly than addition and subtraction - and I am doing that twice.
@cheems082135 жыл бұрын
thank you
@SaurabhMishra07094 жыл бұрын
Thanks for the explanation J Phillius
@095_shaniabalkhi93 жыл бұрын
Thanks bruh!
@kainatmalik17524 жыл бұрын
thank you so much, sir, for your easy and such attractive way of teaching, I never feel bore during listening to your lecture.
@manuelconte6233 жыл бұрын
this video was since 2013 and in 2021 this still good!!!
@agniveshadhikari11 жыл бұрын
Crystal clear explanation
@AllRounder-q9g7 жыл бұрын
My man you are so convincing, truely amazing......
@miguelangelguzmansanchez62869 жыл бұрын
you´re da fuckin bomb dude, ¡viva la indiaaaaa!
@nagenHARP2 жыл бұрын
farrrrrrrrrrrr better than current channels .
@muneerahmad55454 жыл бұрын
Very good bhaiya easily explained very good.keep it up
@ShekharKumar-tn9rl2 жыл бұрын
I know You are no More Sir But seriously I am saying a big thanks to you I haven't found any teacher like you till date you are best of all time sir 🙂 Nation needs Teacher Like You Sir RIP OM Shanti
@hamiltonian4506 жыл бұрын
thanks for the tutorial it helped a lot keep up the great work!!
@harryy0009 жыл бұрын
Question though.For the -1 case meaning when the element is not present in the array since the array is sorted and we know the size of the array,would it not be wiser to initially check if the element we are searching for is gt the size of the array or less than the value in the minimum index(arraypos[0]).Won't this be more effective than doing a if low > high then return -1 which will only be true after completing a recursive/iterative exhaustion of the array?
@nafisfaiyaz75436 жыл бұрын
no, because the key we are searching for can be inside the range of the lowest and highest elements in the arrey and still not present in the arrey. so, if you check only for lowest and highest elements, chances are you will not find the -1 case
@scienceisinaccordancewithi36886 жыл бұрын
YOUR VIDEOS ARE REALLY AWESOME SIR THANKYOU VERY MUCH KEEP UP THE GOOD WORK
@095_shaniabalkhi93 жыл бұрын
Great tutorial. Thanks!
@adityaroshanpatro98614 жыл бұрын
why does that -1 return to its previous one till the top ?? 7:41
@utpalbandyopadhyay16334 жыл бұрын
Great explanation ......!!😊👍
@SoundscapesbyPritam9 жыл бұрын
Why not u have used "while loop" as a base condition in recursive approach? will it be true if we use "while" instead of "if" as the base condition?
@lekanosagie9 жыл бұрын
+Pritam Why use recursion if you're still planning on using loops?
@unboxwithaakash8 жыл бұрын
if loops were to use in recursion then program would gud if remain iterative itself.
@ishaankulkarni494 жыл бұрын
Thanks you so much for making this!!!
@krishanudutta29433 жыл бұрын
Thanks a lot sir for this amazing lecture...
@chinmayrath84947 жыл бұрын
Best explanation. Thanks a lot !
@abhinavtyagi16573 жыл бұрын
why do we need return keyword inside our if and else if statements ?? Bcoz even if we don't return, we still calling the same function i.e. making our recursive call.
@JuanRodriguez-fk2iy4 жыл бұрын
Hello! Amazing video!! I wanted to ask, which method takes less memory? I am still having trouble understanding how recursive functions use memory. Thank you!
@075_ritikkumar74 жыл бұрын
Hey bro. Watch his videos under the playlist recursion. I am sure your doubts would be cleared.
@shaikshabbir44794 жыл бұрын
can we also exit when low == high ?
@rohanmahajan3436 Жыл бұрын
when low == high, then we have to check if A[mid] == x. If that holds true, then we would return mid. Otherwise, if that is false, we return -1. This is still correct, just another way to code it.
@ankitthakar26713 жыл бұрын
We should avoid recursion because sometimes it takes lots of stack space. specifically if you are working in the domain where performance factor is the key.. Your videos are really good.
@sangeethapratapan19046 жыл бұрын
thank you Sir. It helped me a lot.
@mhm51622 жыл бұрын
superb,,good job
@real_manikant8 жыл бұрын
Sir , what is the Space complexity of Binary search in the recursive implementation ????????????? I think it should be O(1) but many people argue that its O(log n)............. Please reply soon
@gluck917 жыл бұрын
O(1) is constant and you do not find solution in one method call, so in this case is O(log) because every time you call method you divide the problem in 2.
@jahnaviization7 жыл бұрын
Can you please do a tutorial on binary search using pointers on a list of names?
@gluck917 жыл бұрын
Good video but not every recursion method can be written in an iterative method, for example : Hanoi Tower problem
@gabriellashebly4 жыл бұрын
what does the arrow mean?
@AnilKumar-jp1cu9 жыл бұрын
Thank you so much......vary nice approach
@amarvishwakarma91738 жыл бұрын
great explanation bro
@MexicanRmz7 жыл бұрын
Thanks bro, great explanation.
@hitrahulmehta11 жыл бұрын
beautifully explained! thanks a lot!
@whiskybhoot10 жыл бұрын
OH WOW
@strawbebbie511 жыл бұрын
so helpful! thanks!
@qwe1237278 жыл бұрын
In your code, Is this correct? mid = low + (high-low)/2;
@ankits3868 жыл бұрын
it is correct ..if u just take tee L.C.M. the value of mid = (low+high)/2 .. mid = low + (high-low)/2 mid= (2low + high -low)/2 mid= (low + high)/2
@tenzin87737 жыл бұрын
Thank you sir!!
@ramankr0022 Жыл бұрын
very helpful.
@pratikshinde34025 жыл бұрын
start at 3:00
@keshavmaheshwari5215 жыл бұрын
how can low be greater than high
@Manish-dh8gx4 жыл бұрын
When we don't find the item in the array our loop increments this happens - (low and high are on same index ) and for loop increments the low by 1
@brunocardoso82776 жыл бұрын
Thank you man!
@AnonymousDev1 Жыл бұрын
I'm a sensitive man . I see recursive function; I panic ! 😵💫
@soulasscape6 жыл бұрын
sir why do we write return with every if else case, we want to sub divide the array and call it recursively so cant we write bs(a,x,mid+1,end) instead of return bs(a,x,mid+1,end) ? i am not able to understand why we write return statement with every recursive call made kindly explain
@yahyashaikhworld8 жыл бұрын
Thanks , but iterative is easier to write
@saidbarke63639 жыл бұрын
thank you.
@Crywolf20311 жыл бұрын
thanks!!!
@kshitijvengurlekar11927 жыл бұрын
Thanks
@vaishnavi50707 жыл бұрын
please do this using pointers
@RAHUL-gf3ft3 жыл бұрын
Jai IIIT ALLAHABAD
@himanshu24877 жыл бұрын
please speak in your natural tone its array not aare its very irritating btw its very help video to me