3rd program

similar to second program, but uses binary search instead of linear
search