- Tubelator AI
- >
- Videos
- >
- Education
- >
- Binary Search Examples: Successful Search | Design & Algorithms | Bhanu Priya
Binary Search Examples: Successful Search | Design & Algorithms | Bhanu Priya
Learn how to implement binary search using examples for successful searches. Understand design principles and algorithms involved in binary search. Watch Lec-13 by Bhanu Priya for an in-depth explanation.
Video Summary & Chapters
1. Introduction 📚
Explanation of binary search and pseudocode
2. Binary Search Example 1 🎯
Successful search example with sorted array
3. Binary Search Example 1 Cont. 🔄
Continuation of successful search example
4. Successful Search Result ✅
Finding the element successfully in the array
5. Binary Search Process 🎯
Exploring the binary search algorithm step by step.
6. Successful Search Outcome ✅
Understanding the successful search completion in binary search.
7. Upcoming Topics 🔍
Previewing the discussion on unsuccessful search in the next video.
Video Transcript
Students, let us continue with the topic binary search. In the previous video I explained about
what is a binary search and what is a pseudocode for the binary search. Now let us take the example.
So here we have to first we have to take the array. So in that array consisting of some elements
we have to find the element. So this binary search may be successful or unsuccessful.
successful search means if the searching element is found then you call it as a successful
search. If the searching element is not found then you call it as an unsuccessful search.
Now let us take two examples. So in the first example let us take the binary search of successful
search means whatever we are searching so in that array we will find an element. So
let us take an array so this is an array consisting of elements 5 7 9 13
32, 33, 42, 54, 56 and 88.
So one thing you have to be noted that a binary search can search the element only the sorted
array.
So it should be a sorted array should be there.
Okay.
A sorted array should be there.
So this is a sorted array.
So all the elements are arranged in an ascending order.
So 5, 7, 9, 13.
so and the values here 0 1 2 3 4 5 6 7 8 9 so the array size is the 9 let us take
the key value key is 33 I want to find the element 33 in this array so how we
fine. So first we have to divide an array that is mid is equal to start plus end by
two. So what is the start value? Start is array zero plus
end is 9, 0 plus 9 by 2 that is 8 means 9 by 2 that is approximately the value is 4.
So this is here you have to check that 33 whatever the divided value that 33 the search
key value here is greater than a of mid so mid is 4 33 is greater than a of 4 so a of 4 is 32
okay but the search value we want is 33 so we have to skip this thing because this is greater than
33 is greater than a of 4 then you have to skip the left side that means you have to take that
start is equal to mid plus one that means now the start will come here this is the start and this is
So we skip this. Why we are skipping this?
Because the method is not correct.
search value that is greater than a of mid so a of mid is the 32 I got okay that is a 4 the 4 a of
4 is 32 so 33 is greater than 32 so just keep this now the start becomes this 5 and end is 9 now again
check so what is the array now so here the array is 33 42 54 56 and 88 okay so
5 6 7 8 9 now again check divide the array into half mid is equal to start
plus end start is 5 end is 9 by 2 so that is 14 by 2 that is 7 so now the
mid becomes 7 so a of 7 is greater than or less than the key value here 33 is
less than A of mid.
A of mid means
of 7. 33 is less than a of 7. So a of 7 is 54. So 33 is less than 54. Okay. So now the
end is mid minus 1. Why I am taking the end is mid minus 1 because 33 is less than a of
7. Less than a of 7 means that is 54 is greater than 33 is less than. So you have to skip
this you have to skip this and we have to search in this left hand side so now
here the end is mid minus 1 so this is a mid value so mid minus 1 and we have to
search from start to mid minus 1 so that's why and is equal to mid minus 1
so now again the search element this to the array consisting of two elements now
33 just you're skipping this 33 and 42 so 33 is 5 42 is 6 now made is equal to
5 plus 6 by 2
So this is approximately 5 means 11 by 2 that is approximately 5.
So now the mid is 5.
Is the mid is equal to key value?