2.6.1 Binary Search Iterative Method
HTML-код
- Опубликовано: 29 сен 2024
- Divide and Conquer Method
Binary Search Method
Iterative Algorithm
Analysis of Binary Search Algorithm
PATREON : www.patreon.co...
Courses on Udemy
================
Java Programming
www.udemy.com/...
Data Structures using C and C++
www.udemy.com/...
C++ Programming
www.udemy.com/...
the audio gets better after 5 minutes or so. Thank you for your videos!!
I was searching for new earphones lol
And it gets worse again at around minute 18 Lol
@@adithyagowda4642 same
@@wirito gradieng
Thanks for the info
Holy shit. I am a senior student of Computer Science and I never REALLY understood these concepts until I watched these videos. I am literally watching the entire playlist to understand Analysis of Algorithms better. You are amazing for taking the time to make these videos. Sending thanks all the way from Texas!
Same here
@@lifeexplorer2965 Same here! (Master's student!)
I am a ECE student i learned all the concepts by my own...i am just here for refresh the concepts...only.
fck textbooks they only made me lost time
you are a senior cs student and you can't understand binary search ? wow, what do they teach you in that school ?
Great video Mr. Bari sir continue to educate CS students as myself, you have done a great job with this series and everyday I wake up knowing that I will learn something new from the master of teaching himself.
Where are u now
A gem , I was tired of watching multiple videos but understood from Bari sir . Thanks a lot sir
I always thought that I'd been kicked in the head by a donkey until I saw this video. You save my life, thank you very much
Thanks alot Sir, your explanations always meet my expectation.
I'm amazed on how you make things look so easy. 👏👏
Sir u r great..plz makes videos on data structures with code and give some problems to practice.
Best explanation forever
The best teacher in the world!
One of the best explanations ever
Missing you sir 🙂
Syed Chand noo
thank you so much they way you understand algo
it was outstanding
Case - Where an element is not present in the tree - instead of quitting when high is less than low, can we use when high==low check that element else return false.
In your code, you return 0 if index is not found, but instead you should return False; returning 0 index will mean that element is found as the first item on array
Here is python code for the same that you explained :
def binarySearch(A,key):
n = len(A)
low = 0
high = n
while (low
Really amaging explainations
Very well explained, thank you so much
Thank you sir for this video
Sir, what would be algorithm if the requirement is if target element is not found, return the closest element. Do we have compare the absolute difference of lowest-target , middle-target& highest-target once the while condition is exited
Why we didn't take the list from "0" index i.e. 0-14 in this case? Thanks.
cause its pseudocode..it doesnt follow faithfully the synatx of C langugae..when u implement it in C language u should declare the function as
int binary_search(int A[ ], int key, int n) //as u know the arrays start form 0 till n-1 if we have declared int A[n];
{
low=0;
high=n-1;
etc...
}
Sir small dought the size of array is 12 so low value is 1 and high value is 12 mid= 1+12/2 in this case what is the mid value can you please conform sir
Really good 👍 thanks so match
Jazakallah Khair
Sir it's really help for me
Guys plzz write mid inside the while loop
Please take few problems on Binary Search and solve it. That is the best way to make others understand Binary Search and it's implementations.
Here is the complete code to find an element in the array:
public class BinarySearch_Iterative {
public static void main(String[] args) {
int[] a = {1, 2, 3, 5, 42, 43, 56};
Arrays.sort(a);
System.out.println(Arrays.toString(a));
System.out.println(fix(a,5));
}//amin
private static int fix(int[] a, int p) {
int start = 0 ; int end = a.length -1;
if(a[start] == p) return a[start];
while(end >= start + 1) {
int mid = start + (end -start)/2 ;
if(a[mid] == p ) return mid ;
if(p > a[mid]) {start = mid + 1 ;}//if
if(p < a[mid]) { end = mid -1 ;}
}
return -1;
}//fix
}//end1
If the mid value is in fraction , what to do ?
Sir please clear my confusion.
If an array contains multiple occurrences of a given element, will a binary search output the position of the first occurrence or the last occurrence or all occurrence?
Search is performed on distinct set of elements only.
@@abdul_bari thank u sir
but the arrays start from 0. we will the first element if we start from 1.
Sir Ji thank you
Sir can u explain plain applications of Euler 'S function on cryptography
God ⚡⚡⚡⚡
Abdul Bari is of the most gifted instructors I have ever seen on online videos. Thank you very much for the level of detail and the clarity of your explanations. I can say that your videos are the solid foundation for literally anyone studying these subjects before watching anything else. Congratulations!
Indeed
Thank You so so much Sir 🙏😊
Algorithms has become "Bachchon ka Khel" after watching your videos! Kudos, you're ultimate!!!
Really
GOD DAMN. I have been through Udacity, Khan Academy, Coursera, MIT etc courses and THIS is by far the best explanation I have encountered. Holy sheeeeeet. Unbelievable.
Note that in practice doing mid = (L+H)/2 is not a good idea because it can cause an overflow since (L+H) can be greater than the list size.
Instead, we should do mid = L+(H-L)/2 to avoid any possible overflow.
Damn I was stuck on this in python for a while, took your advice and it works, you sir are a legend!
we can do the floor division to avoid overflow.
if you start l at 0 and h at length of list -1 you won't overflow
Proudly he is from india❤💕🇮🇳
Proudly he is a MUSLIM.
@@hennaartbyreeka2675 wtf
@@Risefromtheashes689 yeah
@@hennaartbyreeka2675 allah didn't help him to gain knowledge you fool...it was his efforts 😂😂
@@hennaartbyreeka2675 if that is so ...he would have done namaz 😂😂😂😂 and not learn algorithms
So amazing. India needs more teachers like you.
You explain everything about the topic that's what I love the most.
more students like us too bro
lol .. removed headphone and changed settings 4 times thinking the problem was on my end.. btw thanks for your lectures, you are a great teacher.
thanks bro I thought the same
Sir,Array's counting starts from 0 to (n-1) but you have started the counting from 1?Is it possible to do that?
also when the key is not found the return should be -1
usually in sudo code, counting starts from 1 to n.
I regret paying thousands of rupees to my college faculty. Abdul sir's explanation is always on point!
I understand 15 is the amount of nodes, and log2 n. Why 15+1? why +1?
What if array contains even elements? Suppose 16 total
Low=1 and high=16
Mid=(1+16)/2 =8.5
Should we take mid has int so that it becomes int mid=8?
Is that correct?
Same question 🤔................... sir please answer
Most gifted instructor I have ever seen on online videos like this. Thank you very much your explanations.
sir,please make videos on data structures also.
you can buy it from Udemy!
Yeah Purchase the course on Udemy. It is great!!
@@geekyprogrammer4831 is the course instructor himself?
@@gavravdhongadi9824 yep .
I had also bought that course .
It is worth every penny .
Thank you so much!! You make everything so clear. I will continue to learn with you!!
If someone asks me to write binary search in future I will understand and I will write it instead of byhearting. You explained in such a way people will understand to the core. Thank you sir.
what's with the sound?
No
@@abdul_bari No sir everything is fine
indexing in the array stats from 0 right ?
ignoring my university lecture (bcz they just read ) bcz i know Abdul Sir would make me understand in a better way !!!!!!!.
Thanks a lot sir. You are just awesome.
Now Algorithm is My Favourite Subject
Sir at 16:14 you are calculating wrong height. The height of that tree is 3 not 4.(No of edges are counted and not the nodes).
The number of comparison depends upon height of a Complete binary tree as follows:- floor(logn) + 1
Anyways, Your content is awesome.
Ya sir right! By the way your channel is great too!!
Best Binary Search Algorithm Video Ever!!!!!
Superb!!! Sir, you are great.... Fantastic... You made this course a piece of cake.
are you studying analysis and design of algorithm?
sir i have only watched this video of yours and i am already your fan! this was very very very much helpful! sir charan kahan hai aapke ashirvaad de do plz
God Bless You.
This is really great video thanks a lot
play the video at a faster speed to mitigate the audio issues
your surname in armenian means kind , thank you for your videos
you help me alot ,
thanks for sharing this concept,
now i got how binary search works,
really nice work, wonderful presentation
Sir you’re best teacher ever
Ma Shaa Allah
May Allah reward you for this explanation
May God bless you and make it in the balance of your good deeds
Best 19 minutes ever❤❤❤❤
Sir, generally i understand your videos, i understand the concept of algorithms but i want to make practice for understand better, what would you suggest for practice? Thank you
geeksforgeeks.org
I think you should firstly Master the Data Structures and practice these algorithms on any competitive Programming site. I personally use Hackckerrank and Codechef.
Assalamualaikum thanks a lot I understand it
So good! Much more understandable than the video of self-claimed "competitive programmers" out there!
Sir Aapko Chumma Dene ka Karta h ek video m hi kai baar. M apni aukaat badhane k liye acchi companies ki preparation kar rha hu. Now its seems possible.
For your information Abdul sir also have DSA course in Udemy & the price is just 350-500 INR ($4).
JUST GO and buy that course he will make your career
Can we write else if(key
U can
Nice tutorials.While making videos, plz give basic details of the topic as well as its implementation in java.I apprerciate your effort to share knowledge which will have global reach.
Thank you, Abdul. Quality materials!
Agar mjhe 30 Lakhs k upper ka Package mila tou m aapko duniya m kahi bhi dhood nikalunga ar aapse milne aaoonga. Promise
Your explanations are brilliant! Greetings from Russia
Sir you are great..helpful materials but it will be more useful if you explain topics from more basic concepts and would be best if you discuss these concepts in java or c# simultaneously..huge respect and love for you sir ❤️🙏🙏...
Sir can we take l=0 and h=14 ?
yes
Bari ji Keerthan holla aapka bahut bada fan hai, aur aapka ghanta bajata hai hamara hostel mei.. thank u
In the algorithm, low=1
Where index of the array starts from 0..how is this working??
Plz help
He is Bramha Of algorithms.
So far the best video on this topic I have ever watched he makes it looks simple and easy to comprehend. Thumbs up Sir
great work !! can't thank you enough it really boosted my confidence
the simplicity and thoroughness of your explanations are beautiful. thank you sir.
I love this
God raised such an Amazing Teacher!
Glory To God
Sir thanks a lot for making such awesome videos .Your videos are too good! You teach far better than an average teacher.
n=12000 h toh binary search algorithm ka maximum running time kya hoga answar plz
Abdul Sir, as we know that the list/array starts with 0, so ideally in our case the list shud had started with 0 and ended with 14, isn't that correct? In that case the result would come within 2nd step.....May be my understanding is wrong, plz correct me.
Sir, i have confusion at level 0 there is 1 node ,at 1st level there is 2^1 node , at 2nd level there is 2^2 node and at 3rd level there is 2^3 node so at kth level there is 2^k node ... so finding time complexity we do 1+2^1+2^2+2^3.....2^k ,it form of GP , so we can write 2^(k+1)-1 ; assuming n-k=0 ; n=k we can write 2^(n+1)-1=2^n 2^2 +1 ,so time complexity will be o(2^n)....why it can't be o(2^n) ?
because we are not going to all the nodes, we take only 1 path, what is displayed is all possibilities while searching, but if we search a element we explore only 1 path to the leaf in max worst case scenario.
I've seen some kind of problems that the solution is to do a binary search on the answer, can someone pls explain me that
I can't find any video about it.
Sir, U explained this algorithm with so ease........ Thanku so much for ur guidance.....Looking forward for more such tutorials.
all i understand but i can't understand how can we consider the low index as 1.... it should be zero.....
can we check low and high for key before dividing array for mid (then we check it on and and so on ) me be the number in the location of low or high
Well done sir from Pakistan 🇵🇰👍
Sir, Sachmuch maine aap jaisa explain krne wale sir nahi dekhe,
You will a good motivation towards understanding programming in a good manner ..
And plz upload concepts regarding c++ and data structures..
Again thank you for such great explanation....🤗👍🏻
Sir I have watched all of your lecture,kindly sir insertion sort per koi video zaror bnay
The audio gets better after 5:25
echo is been produced the entire vedio sir, n gud luck for the productive lectures u gave, kindly upload some more fruitful vedios on computer architecture or other subjects
Thank you. These videos are great tutorials.
Nice, Good Explanation
thanks bro there were so many recurrence relations tho but i guess if you're actually gonna do cs thats pretty good
Sir what if the mid value comes in decimal form...say like L=1 and H=4 then mid (1+4)/2 ...then it will be 2.5 , what should i do in this situation.. kindly reply
Rule :- Always takes integer value.
. That is if 2.5 takes 2 ... ### neglect decimal part .. Hope it is clear
Sir ,if we are supposed to do range searching i.e. for finding all the values in a sorted array , whose values fall between L and U (inclusive),where L
Easy!! find indexes of lower_bound == L and upper_bound== U from the array. All the elements can be found if we know lower and upper bound. Lower bound and upper bounds can be found using binary search. So complexity will be O(logn).
The explanations were so precise and clear cut. Thankyou so much Sir :)