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.
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.