Perfect Binary Search implementation