Consider an array is arr of size len elements. We want to search for a number, numb, in this array, arr. Here are the steps to search for numb in the arr array using binary search:
- Initialize two variables, lower and upper.
- Calculate the middle location of the array.
- If the value to search, numb, is found at location arr[mid] then display Value found and exit (that is, jump to step 8).
- If your search value is larger than the array's middle value, confine the search to the lower half of the array. So, set the lower limit of the array to the array's middle value.
- If your search value is smaller than the array's middle value, confine the search to the upper half of the array. So, set the upper limit of the array to the array's ...