Example : Example Let A[9] = { 4,8,10,12,30,40,50,55,60 } be an array containing 9 elements sorted in ascending order and 12 be the data /item to be searched.
The middle position of the array (0….8) is 4 (mid = 4), and the value of the element at position four is 30 ( A[mid] = 30 ).
A[9] = { 4 , 8 , 10 , 12 , 30 , 40 , 50 , 55 , 60 }
?middle
Since the data < A[mid] i.e. (12 < 30 ), therefore the data lies in the upper
half ( 0….4) division (say subdivision_1) of the array.The middle position of the upper half division of the array (0….4) is 2 (mid = 2) and the value of the element at position two is 10 i.e. A[2] = 10 i.e. A[mid] = 10
A[9] = { [ 4 , 8 , 10 , 12 , 30 ] , 40 , 50 , 55 , 60 }
?middle
Now the data > A[mid] i.e. (12 > 10) which indicates that the data lies in the lower half of the newly divided array i.e. subdivision1. The newly divided array (say subdivision_2) will now contain only 3 elements (10, 12,30 ). Again the middle position of the array subdivision_2 is 3 and the value of the element at position 3 is 12 i.e. A[3]=12
a[9 ] = { [4 , 8 , (10 , 12 , 30) ], 40 , 50 , 55 , 60 }
? middle
At this stage since the data 12 is equal to A[3], hence the search is over. In the above example, if the data were to be 15 instead of 12, then we would conclude that “ the data is not in the list ” because the array would be left with only one element and can not be further divided