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

preview_player
Показать описание
Support Simple Snippets by Donations -
--------------------------------------------------------------------------------------------- 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

Simple Snippets Official Website -
Simple Snippets on Facebook -
Simple Snippets on Instagram -
Simple Snippets on Twitter -
Simple Snippets Google Plus Page -
Simple Snippets email ID -

#binarysearch #searchingalgorithms #datastructures
Рекомендации по теме
Комментарии
Автор

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 ✌

SimpleSnippets
Автор

hey simple snippets
u r more then anything
ur videos always eliminate confusion
thnkksss alot

romaisasehrish
Автор

I will suggest your channel to others from now on becoz i found it very helpful more than others with good explanation nd examples

Lalinxdboom
Автор

U will definetely earn a lot , love ur videos.

jollyllb
Автор

it was truely amazing .... thanks for this amazing video lecture

shahghanikhan
Автор

Top to Bottom samajh Aya❤️
Also the way he gives every code❤️
Tanmay Bhai boss

nafisahmed
Автор

why we don' t use mid=(left+right)/2 at place of mid=left+(right-left)/2

kanharajput
Автор

Bro, What's the significance of mid = left+(right-left)/2, Why not just ( left+right)/2

mjprayog
Автор

You made this so simple to understand. Many thanks sir!

avvii
Автор

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.

ayushagarwal
Автор

hey simple snnipet ur videos are amazingly gud .Thanks for providing such a great source.

prekshamishra
Автор

Hi, Tanmay Sakpal I believe you are doing great! anyway, Binary Search is made the simplest of the simple.

vijaysinghchauhan
Автор

AWESOME explanation... as usual <3... Peace

dibbyabarua
Автор

Great work bhaiya this is best channel. bhaiya can you please make a video on Dynamic Programming?

abhijeetbasfore
Автор

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

dishanamdev
Автор

Why loop, u can go directly to the index of mid each time and find that index value to match

HoneySinha
Автор

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???

slimysnail
Автор

If we hv to find 95 then.. Or -5 then what will be the logic

dolibelel
Автор

20:37 Sir, how will the result if you change return -1 to return 0?

adiflorense
Автор

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

mahesh-jgzx