"By the way, why do you switch from a binary search to a linear search to find the beginning of a match?"
Since the array could contain duplicate entries, I just want to find the first (if begin = 1) or last (if begin=0) of the entries. Is there a better way to do it that to search linearly after I find my query?