my first pass at binary search
sedgewick's more concise version