binary search algorithm in 2D