Introduction
In this blog, we will discuss the Binary Search technique. In Linear Search, first, we have to enter the elements in the array and then, we have to iterate the array for finding a particular value. Here, the array can either be in a sorted or an unsorted manner. If the particular searching element is found, then we have to return the element and position from the array. If not, we have to print the message like "Element not found in the array".
In a Binary Search technique, first, we have to enter the elements into the array and then, we have to sort the array in ascending or descending order based on our convenience. Then, we have to set the array's lower and upper bound. With those upper and lower bounds, we have to find the mid-value and iterate the array if the mid-value is greater or smaller than the searching element.
Then, we have to divide the array elements again. Now, we have to search for the lower bound, upper bound and mid value and do it recursively until the searching element is found. If the particular searching element is found, then we have to return the element and position from the array. If not, we have to print the message like "Element not found in the array". So, let's get started.
Note
For different Python IDEs, we have different ways to execute, however, the result remains the same. For those who are using Visual Studio IDE for Python, the process will be something as shown below.





Gaurav GahlotPosted Oct 26, 2018, 2:09 AM
Hi Kartik! I think the output images are incorrect. Please fix them as soon as possible. Also, I would recommend to clean up your code a bit and mind the indentation. Since this is a good topic and many readers would want to use the code, I would suggest to add appropriate comments.