binary search algorithm

  1. Start by defining the range of the search, which includes the minimum and maximum indices of the array or list.

  2. Calculate the middle index of the range using the formula (min_index + max_index) / 2.

  3. Compare the middle element with the target value that you are searching for.

  4. If the middle element is equal to the target value, the search is successful, and the index of the target value is returned.

  5. If the middle element is greater than the target value, adjust the range to exclude the upper half, setting max_index to (middle_index - 1).

  6. If the middle element is less than the target value, adjust the range to exclude the lower half, setting min_index to (middle_index + 1).

  7. Repeat steps 2-6 until the target value is found or the range is empty, indicating that the target value does not exist in the array or list.