Binary search is an essential search algorithm that takes in a sorted array and returns the index of the value we are searching for
Do this with the following steps:
- Find the midpoint of the sorted array.
- Compare the midpoint to the value of interest.
- If the midpoint is larger than the value, perform binary search on right half of the array.
- If the midpoint is smaller than the value, perform binary search on left half of the array.
- Repeat these steps until the midpoint value is equal to the value of interest or we know the value is not in the array.
Comments
Post a Comment