int BinarySerach(A, begin,end,elem)
l<-begin;
h<-end;
while l<=h
mid=(l+h)/2;
if A[mid]=elem
then return mid;
if A[mid]>elem
then h=mid-1
else
h=mid+1
return NIL
BinarySearch(A,begin,end,elem)
l<-begin
h<-end
if l>h
then return NIL
mid<-(l+h)/2
if A[mid]=elem
return mid
if A[mid]<elem
BinarySearch(A,mid+1,h,elem)
else
BinarySearch(A,l,mid-1,elem)
l<-begin;
h<-end;
while l<=h
mid=(l+h)/2;
if A[mid]=elem
then return mid;
if A[mid]>elem
then h=mid-1
else
h=mid+1
return NIL
BinarySearch(A,begin,end,elem)
l<-begin
h<-end
if l>h
then return NIL
mid<-(l+h)/2
if A[mid]=elem
return mid
if A[mid]<elem
BinarySearch(A,mid+1,h,elem)
else
BinarySearch(A,l,mid-1,elem)