Binary Search Algorithm (Working, Algorithm & Diagram) in Data Structures | Part 1 | DSA

  Рет қаралды 52,871

Simple Snippets

Simple Snippets

Күн бұрын

Support Simple Snippets by Donations -
Google Pay UPI ID - tanmaysakpal11@okicici
PayPal - paypal.me/tanmaysakpal11
--------------------------------------------------------------------------------------------- Binary search algorithm falls under the category of interval search algorithms. This algorithm is much more efficient compared to linear search algorithm. Binary search only works on sorted data structures. This algorithm repeatedly target the center of the sorted data structure & divide the search space into half till the match is found.
The time complexity of binary search algorithm is O(Log n).
Working -
1. Search the sorted array by repeatedly dividing the search interval in half
2. Begin with an interval covering the whole array.
3. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half.
4. Otherwise narrow it to the upper half.
5. Repeatedly check until the value is found or the interval is empty
Pseudo code for Binary Search Algorithm -
1. take input array, left, right & x
2. START LOOP - while(left greater than or equal to right)
2.1 mid = left + (right-left)/2
2.2 if(arr[mid]==x) then
2.2.1 return m
2.3 else if(arr[mid] less than x) then
2.3.1 left = m + 1
2.4 else
2.4.1 right= mid - 1
END LOOP
3. return -1
Full DSA playlist - • Introduction to Data S...
Full Code & Theory article - simplesnippets...
C++ Programming Tutorials for Beginners Course - • Introduction to Comput...
Simple Snippets Official Website -
simplesnippets....
Simple Snippets on Facebook -
/ simplesnippets
Simple Snippets on Instagram -
/ simplesnippets
Simple Snippets on Twitter -
/ simplesnippet
Simple Snippets Google Plus Page -
plus.google.co...
Simple Snippets email ID -
simplesnippetsinfo@gmail.com
For More Technology News, Latest Updates and Blog articles visit our Official Website - simplesnippets....
#binarysearch #searchingalgorithms #datastructures

Пікірлер: 56
@SimpleSnippets
@SimpleSnippets 5 жыл бұрын
Hey Guys, if you want more such tech educational videos on this channel then please support me by subscribing to this channel & also share it with your friends as it helps me create more content just for you ✌
@romaisasehrish262
@romaisasehrish262 4 жыл бұрын
hey simple snippets u r more then anything ur videos always eliminate confusion thnkksss alot
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
Thank you so much buddy, I am glad to hear this from you. Please do share the videos with your friends & Definitely SUBSCRIBE. Thats the biggest help & support 😇✌
@shahghanikhan4328
@shahghanikhan4328 2 жыл бұрын
it was truely amazing .... thanks for this amazing video lecture
@Lalinxdboom
@Lalinxdboom Жыл бұрын
I will suggest your channel to others from now on becoz i found it very helpful more than others with good explanation nd examples
@jollyllb9159
@jollyllb9159 4 жыл бұрын
U will definetely earn a lot , love ur videos.
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
Thank you so much 😀 Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇
@nafisahmed3607
@nafisahmed3607 3 жыл бұрын
Top to Bottom samajh Aya❤️ Also the way he gives every code❤️ Tanmay Bhai boss
@closetoheart6120
@closetoheart6120 Жыл бұрын
bhai is this playlist good for college exams?
@mjprayog
@mjprayog 4 жыл бұрын
Bro, What's the significance of mid = left+(right-left)/2, Why not just ( left+right)/2
@h_s_4049
@h_s_4049 2 жыл бұрын
Suppose your 'left' and 'right' are 16 bit unsigned integers. That means, they can only have a maximum value of 2^16=65536. Consider this, left = 65530 right = 65531 If we added them first, (left+right) would end up being junk since that big a number (131061) cannot be stored in a your 16-bit integer. And so, mid would be a wrong value.
@tahahuraibb5833
@tahahuraibb5833 2 жыл бұрын
@@h_s_4049 Thanks mate!
@kanharajput5443
@kanharajput5443 3 жыл бұрын
why we don' t use mid=(left+right)/2 at place of mid=left+(right-left)/2
@shahinphatan4865
@shahinphatan4865 2 жыл бұрын
Fan of your lecture 🖤
@avvii1
@avvii1 2 жыл бұрын
You made this so simple to understand. Many thanks sir!
@ayushagarwal8054
@ayushagarwal8054 4 жыл бұрын
I will try my best to share your videos Sir keep on the good work, i definitely would have given you 1 k likes if possible 😍😍 thank u soo much for your other video.
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
Thank you so much brother. These words itself mean so much to me. Your support is the biggest motivation my Ayush 😇 Keep sharing the channel with your friends. There are 400+ videos on our channel so do check them out ✌️
@vijaysinghchauhan7079
@vijaysinghchauhan7079 4 жыл бұрын
Hi, Tanmay Sakpal I believe you are doing great! anyway, Binary Search is made the simplest of the simple.
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
Thanks a ton Vijay
@mahjabinbintemannan8924
@mahjabinbintemannan8924 2 жыл бұрын
This lecture was amazing
@prekshamishra9921
@prekshamishra9921 4 жыл бұрын
hey simple snnipet ur videos are amazingly gud .Thanks for providing such a great source.
@dibbyabarua9499
@dibbyabarua9499 4 жыл бұрын
AWESOME explanation... as usual
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
Thank you so much buddy🙏 Please support me by sharing the videos and our channel with your friends too. Thats the biggest help and support you can provide 😇
@parthkeskar8354
@parthkeskar8354 3 жыл бұрын
Thanks for explaining
@masumali8356
@masumali8356 15 күн бұрын
lovely
@nitismita1035
@nitismita1035 2 жыл бұрын
Thank you Sir ❤💌
@dishanamdev2620
@dishanamdev2620 4 жыл бұрын
In the last case uh said when we pass 115 as x left will become greater than right but how it will become greater thn right we just pssed a false value tht is not in the array.... Plz telll
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
I didnt really get your question. Can you please pin point the timecode where I said that. ✌
@dishanamdev2620
@dishanamdev2620 4 жыл бұрын
@@SimpleSnippets you started at 19.50 at last One thing i want to say You are too much amazing, and your videos are more understandable than other Thanku a lot
@gauripawar356
@gauripawar356 3 жыл бұрын
Yes dude I saw this vdo right now... Nd I had same doubt...
@mdtausifahmed6205
@mdtausifahmed6205 2 жыл бұрын
amazing
@mohdarish4195
@mohdarish4195 3 жыл бұрын
Super se bhi upper
@abhijeetbasfore6816
@abhijeetbasfore6816 3 жыл бұрын
Great work bhaiya this is best channel. bhaiya can you please make a video on Dynamic Programming?
@SimpleSnippets
@SimpleSnippets 3 жыл бұрын
This will take time but eventually I'll cover it🤘
@nitismita1035
@nitismita1035 2 жыл бұрын
Thank u 💓💗💖💛
@sriramadithya4799
@sriramadithya4799 3 жыл бұрын
Thanks
@HoneySinha001
@HoneySinha001 2 жыл бұрын
Why loop , u can go directly to the index of mid each time and find that index value to match
@sureshyedge3738
@sureshyedge3738 5 жыл бұрын
Thanks!!👍👍
@SimpleSnippets
@SimpleSnippets 5 жыл бұрын
Most welcome 🤟please do share the video with your friends too ✌️
@nidhinhari8397
@nidhinhari8397 4 жыл бұрын
Sir Which textbook are you using?
@mahesh-jg3zx
@mahesh-jg3zx 5 жыл бұрын
Sir you are explaning 💪 awesome but why you not tried to do videos in unacademy sir, actually I'm searching a videos on sorting and searching in unacademy it's there but these particular information is not given please do the videos in unacademy also
@SimpleSnippets
@SimpleSnippets 5 жыл бұрын
Thank you mahesh for the compliments. And yes I did see how unacademy works, I found it very restrictive when it comes to making videos only using their mobile app. I like it to be flexible cause I shoot my videos on various devices 😇 Also please do share this video with your friends buddy 😁
@venkateshprasads8361
@venkateshprasads8361 3 жыл бұрын
plz make a video on Fibonacci search
@slimysnail6071
@slimysnail6071 2 жыл бұрын
PLIS HELP :( mid =(left + right)/2.... for the first one mid = ( 0 + 9)/2 = 4(int) why did you complicated it typing " mid = left + ( right - left)/2 " ? AM I MISSING ANYTHING?? CAN I USE mid = (left + right)/2???
@nochannel2103
@nochannel2103 3 жыл бұрын
Mid = (left + right) is also currect 🤷🏻‍♂️
@israrqayyum7
@israrqayyum7 9 ай бұрын
@adiflorense1477
@adiflorense1477 4 жыл бұрын
20:37 Sir,how will the result if you change return -1 to return 0?
@katieplayz6079
@katieplayz6079 3 жыл бұрын
he litterly said if it's 0 or other than that it i'll placed in the array as the index 0 because you said return 0;
@dolibelel2113
@dolibelel2113 4 жыл бұрын
If we hv to find 95 then.. Or -5 then what will be the logic
@mallipallianusha7020
@mallipallianusha7020 4 жыл бұрын
What if there is an element in more than 1 place?let's say it's repeating.!
@SimpleSnippets
@SimpleSnippets 4 жыл бұрын
Then there has to be extra code to take care of that scenario which will make this complicated
@sakshisengar7709
@sakshisengar7709 4 жыл бұрын
why cant the mid be mid=(left+right)/2............???
@ar3568row
@ar3568row 4 жыл бұрын
@@SimpleSnippets i did , but got the same thing from both .
@ar3568row
@ar3568row 4 жыл бұрын
did you get it ?
@ChandrapalSd
@ChandrapalSd 4 жыл бұрын
I think both are same
@shirsharay
@shirsharay 4 жыл бұрын
Do the math. It's the same.
Binary Search Algorithm C++ Code in Data Structures | Part -2 | DSA
14:50
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 160 М.
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 62 МЛН
C++ Programming: Binary Search Algorithm
14:53
ReelLearning
Рет қаралды 219 М.
Sorting Algorithms Explained Visually
9:01
Beyond Fireship
Рет қаралды 536 М.
Linear Search Algorithm - Theory + Code + Questions
1:15:44
Kunal Kushwaha
Рет қаралды 792 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 471 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 652 М.
Binary Search - A Different Perspective | Python Algorithms
8:56
Binary Search Algorithm | C Programming Example
11:41
Portfolio Courses
Рет қаралды 55 М.
Algorithms Explained for Beginners - How I Wish I Was Taught
17:38
Internet Made Coder
Рет қаралды 347 М.
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 62 МЛН