master-algorithms-py/searching
2023-08-03 19:34:22 -07:00
..
binary_search.py Update binary_search.py 2023-07-31 15:41:56 -07:00
bs_find_pair_nums.py Create bs_find_pair_nums.py 2023-08-03 19:34:04 -07:00
find_minimum_rotated_array.py Create find_minimum_rotated_array.py 2023-07-31 16:09:47 -07:00
find_peak_element.py Create find_peak_element.py 2023-07-31 15:57:30 -07:00
README.md Update README.md 2023-07-31 16:18:44 -07:00
rotated_array.py Rename bs_rotated_array.py to rotated_array.py 2023-08-03 19:34:22 -07:00
sqrt_x.py Create sqrt_x.py 2023-07-31 15:10:15 -07:00

searching



  • a binary search operates on a contiguous sequence with a specified left and right index. this is called the search space.

  • binary searching is composed of 3 sections:

    • pre-processing: sort if collection is unsorted
    • binary search: using a loop or recursion to divide search sapce in half after each comparison
    • post-processing: determine viable candidates in the remaining space
  • there are 3 "templates" when writing a binary search:

    • while left < right, with left = mid + 1 and right = mid - 1
    • while left < right, with left = mid + 1 and right = mid, and left is returned
    • while left + 1 < right, with left = 1 and right = mid, and left and right are returned