Using the example: This code uses binary search it splits between arr[1]
and arr[2]
. In the loop the mid is 10 and since it is greater than 5 arr[mid] > arr[mid + 1]
h=1 which is the index of 10. It goes through the loop again and checks between 0 and 10 and the index of 10 is returned.