Corrected Binary Search algorithm