This is code for binary search.