1. Tubelator AI
  2. >
  3. Videos
  4. >
  5. Education
  6. >
  7. Binary Search Examples: Successful Search | Design & Algorithms | Bhanu Priya

Binary Search Examples: Successful Search | Design & Algorithms | Bhanu Priya

Available In Following Subtitles
English
Variant 1
Posted on:
Video by: Education 4u
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.
tubelator logo

Instantly generate YouTube summary, transcript and subtitles!

chrome-icon Install Tubelator On Chrome

Video Summary & Chapters

0:00
1. Introduction 📚
Explanation of binary search and pseudocode
0:42
2. Binary Search Example 1 🎯
Successful search example with sorted array
3:20
3. Binary Search Example 1 Cont. 🔄
Continuation of successful search example
6:27
4. Successful Search Result ✅
Finding the element successfully in the array
7:08
5. Binary Search Process 🎯
Exploring the binary search algorithm step by step.
8:10
6. Successful Search Outcome ✅
Understanding the successful search completion in binary search.
8:12
7. Upcoming Topics 🔍
Previewing the discussion on unsuccessful search in the next video.

Video Transcript

0:00
Students, let us continue with the topic binary search. In the previous video I explained about
0:07
what is a binary search and what is a pseudocode for the binary search. Now let us take the example.
0:14
So here we have to first we have to take the array. So in that array consisting of some elements
0:22
we have to find the element. So this binary search may be successful or unsuccessful.
0:29
successful search means if the searching element is found then you call it as a successful
0:35
search. If the searching element is not found then you call it as an unsuccessful search.
0:42
Now let us take two examples. So in the first example let us take the binary search of successful
0:48
search means whatever we are searching so in that array we will find an element. So
1:01
let us take an array so this is an array consisting of elements 5 7 9 13
1:12
32, 33, 42, 54, 56 and 88.
1:19
So one thing you have to be noted that a binary search can search the element only the sorted
1:27
array.
1:28
So it should be a sorted array should be there.
1:36
Okay.
1:37
A sorted array should be there.
1:38
So this is a sorted array.
1:40
So all the elements are arranged in an ascending order.
1:42
So 5, 7, 9, 13.
1:44
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
1:56
the key value key is 33 I want to find the element 33 in this array so how we
2:06
fine. So first we have to divide an array that is mid is equal to start plus end by
2:18
two. So what is the start value? Start is array zero plus
2:24
end is 9, 0 plus 9 by 2 that is 8 means 9 by 2 that is approximately the value is 4.
2:36
So this is here you have to check that 33 whatever the divided value that 33 the search
2:45
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
3:02
okay but the search value we want is 33 so we have to skip this thing because this is greater than
3:11
33 is greater than a of 4 then you have to skip the left side that means you have to take that
3:19
start is equal to mid plus one that means now the start will come here this is the start and this is
3:30
So we skip this. Why we are skipping this?
3:35
Because the method is not correct.
3:36
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
3:43
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
3:55
check so what is the array now so here the array is 33 42 54 56 and 88 okay so
4:11
5 6 7 8 9 now again check divide the array into half mid is equal to start
4:21
plus end start is 5 end is 9 by 2 so that is 14 by 2 that is 7 so now the
4:32
mid becomes 7 so a of 7 is greater than or less than the key value here 33 is
4:43
less than A of mid.
4:46
A of mid means
4:47
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
5:01
end is mid minus 1. Why I am taking the end is mid minus 1 because 33 is less than a of
5:09
7. Less than a of 7 means that is 54 is greater than 33 is less than. So you have to skip
5:18
this you have to skip this and we have to search in this left hand side so now
5:25
here the end is mid minus 1 so this is a mid value so mid minus 1 and we have to
5:33
search from start to mid minus 1 so that's why and is equal to mid minus 1
5:39
so now again the search element this to the array consisting of two elements now
5:46
33 just you're skipping this 33 and 42 so 33 is 5 42 is 6 now made is equal to
5:57
5 plus 6 by 2
5:59
So this is approximately 5 means 11 by 2 that is approximately 5.
6:06
So now the mid is 5.
6:08
Is the mid is equal to key value?
shape-icon

Download extension to view full transcript.

chrome-icon Install Tubelator On Chrome