I was just going through the basics and I wanted to verify that I still knew how to do a binary search. If I remember correctly these are the steps:
– Set a left pointer at the beginning of the sorted array
– Set a right pointer at the end of the sorted array
– Calculate the middle between those two pointers(If there is no exact middle, truncate the number) and set the a middle pointer there
– Check if the middle is the number you are looking for. If it is return
– If the element at middle is greater than the element you are looking for set the left pointer to middle + 1
– If the element at middle is lower than the element you are looking for set the right pointer to middle – 1
– Repeat until the number is found or left is greater than right (not found)