intbinary_search(int[]A,intkey,intimin,intimax){// continue searching while [imin,imax] is not emptywhile(imin<=imax){// calculate the midpoint for roughly equal partitionintimid=imin+((imax-imin)/2);if(A[imid]==key)// key found at index imidreturnimid;// determine which subarray to searchelseif(A[imid]<key)// change min index to search upper subarrayimin=imid+1;else// change max index to search lower subarrayimax=imid-1;}// key was not foundreturn-1;}