BINARY SEARCH () :
A is a sorted array with N elements. ITEM is the value to be searched.BEG is first element and END is last element in the array. MID is the middle value.
Step I : [ initialization ] Set BEG = 1 and END = N
Step II : Set MID = ( BEG + END ) / 2
Step III : Repeat While ( BEG <= END ) and ( A[MID] != ITEM )
Step IV : If ( ITEM < A[MID] ) Then
Step V : Set END = MID – 1
Step VI : Else
Step VII : Set BEG = MID + 1
[ End of If ]
Step VIII: Set MID = ( BEG + END ) / 2
[ End of while loop ]
Step IX : If ( A[MID] == ITEM ) Then
Step X : Print: ITEM exists at location MID
Step XI : Else
Step XII : Print: ITEM doesn’t exist
[ End of If ]
Step XIII : Exit
Explained Using Figure: