binary searchthe binary search supposes that the


Binary Search:

The binary search supposes that the vector has been sorted first. The algorithm is just similar to the way it works whenever looking for a name in a phone directory (that is sorted in alphabetic order). To find the value of a key, look at the element in the middle.

  • If that is the key, then the index has been found.
  • When it is not the key, decide whether to search the elements before or after this place and adjust the range of values in which the search occurs and begin this process again.

To implement this, we will use variables low and high to identify the range of values in which to search. To start, the value of low will be 1, and the value of high will become the length of the vector. The variable mid be the index of the element in the middle of the range from low to high. When the key is not found at mid, then there are two possible way to adjust the range. When the key is less than the value at mid, we change high to mid - 1. When the key is greater than the value at mid, then we change low to mid 1.

 

Request for Solution File

Ask an Expert for Answer!!
Applications of MATLAB: binary searchthe binary search supposes that the
Reference No:- TGS0175356

Expected delivery within 24 Hours