 Welcome to the lecture series on binary search algorithm. At the end of this session, student will be able to differentiate linear search and binary search, describe the working of binary search algorithm, implement binary search on an array. We will be discussing the searching strategies, understanding working of binary search, and finally implementing binary search on an array. In our day-to-day life, search is one of the most common activity that we all do. For example, imagine it's a Sunday and you're watching a new web series. A point comes when you realize you are hungry and there's nothing to eat at home. How will you handle this situation? Swiggy, right. This is the most important thing or rather only thing that we all do today, search, search online. I hope this gives you a clear example of searching algorithm in real life context. Moving on to the programming side of a real life application of searching. Given a sorted array of n elements, write a function to search a given element x in an array. So, to search an element from a sorted array of n elements in computer, we have two popular computer algorithms. Those are linear search and binary search. In this video, we will be first understanding linear search and then in detail, seeing binary search. Let's find out a quick view of both searching process and then we'll discuss their differences. So, let's start with a simple approach that is to do linear search. Linear search is basically a sequential search made all over the items one by one. Here, every item is checked and if a match is found, then the particular item is returned. Otherwise, it continues till the end of the data. If the match doesn't occur, no element is returned, minus one is returned. Here, you can see the item to be searched is 33 and linear search keeps on comparing with every one one by one and when it is found out, it returns. That is over here. The time complexity of the above algorithm is o of n. This is better when the n is less. However, when the n is in multiples of thousand, the alternative approach would be binary search. Now, let's see binary search. Binary search is an efficient algorithm for finding an item from a sorted list of item. Binary search works on the principle of divide and conquer. It works repeatedly by dividing in half the portion of the list that could contain the item until you have narrowed down all the possible locations to just one. Binary search looks for a particular item by comparing the middle element. That is the middlemost element of the collection. If the match occurs, then the index of the item is returned as seen over here. If the match, like if the middle element is greater than the item, then the item is subsurged in the sub array to the left of the middle element. Otherwise, the item to be searched for the sub array to the right of the middle element. This process, as you can see over here, it depends. If found, it is returned. If it is less, search only the right part. If it is less, search only the left part. Now, this depends on dividing the binary search. For binary search to work, it is mandatory for the array to be sorted. We shall now learn the process of binary search with a pictorial example given here. Our sorted array. The following is our sorted array and let us assume that we want to search the location of value 201 using binary search. First, we shall determine half of the array by using the formula. Low is the leftmost element and right and high is the rightmost element in the given sorted array. We calculate the mid using the formula, mid is equal to low plus high minus low divided by 2. Now, here the number to be searched is 201. This is the low. This is the high. Now, we compare the value by calculating the mid. So, here it is 0 plus 12 by 2 that is 6 integer value of 4.5. So, 6 is the mid of the array. Now, we compare the values stored at location 6 with the value being searched that is 201. We find that the value at location 6 is 101 which is not a match. As the value is greater than 101, we have a sorted array. So, we know that the target value must be in the upper portion, this part. So, that is this part. So, we change our load to mid plus 1 and find a new mid value again. Next, our now new mid is 9. We compare the value stored at location 9 with a target value that is 201. The value stored at location 9 is not a match. Rather, it is more than what we are looking for. As the value is greater than that is 179, the target value must be in the upper portion of the array. So, the value must be in the lower part of this location. Hence, we calculate the mid again. This time the mid is 11 as seen over here. Now, the mid is 11 as the target value is as the target value is less than the value stored at location 11. We now look for the value in the lower part of this location. Hence, we calculate the mid again. This time it is 10. We compare the value stored at location 10 with our target value. We find that it is a match. That is binary search halves the searchable item and thus reduces the count of comparisons to be made to very less number. So, we conclude that our target value is stored at location 10. A quick recap of the entire process once again as we have seen this was a sorted array. We wanted to search the element 201. We calculated the mid by using the formula low plus high and each time we compared it and based on that we decided to either move left or right from the mid element. Here the mid was 101 that is less than 20. Therefore, we move towards the mid by making it 7. Then calculating the new mid further compared is comparing it once again. We calculated the mid was not a match and finally the mid itself was a match and now the value that we were searching is obtained at location 10. Now pause the video for some time and answer the following. Binary search can be categorized into which of the following, brute force technique, divide and conquer, 3D algorithm, dynamic programming. Yes, divide and conquer. Since mid is calculated for every iteration or recursion, we are dividing the array into half and then try to solve the problem. Next question given an array and key is equal to 88, how many iterations are done until the element is found? You need to calculate answer two iterations. Explanation first iteration at mid equal to 77, second iteration mid equal to 88. These are the references. Thank you.