I wonder, can binary search be applied on a 2D array?
If your array is sorted by increasing values, then, do a binary search on the array A[i][0]
by varying i
, then a binary search on A[i*][j]
by varying j
, where i*
is the row containing the desired value.
Finding i*
would be done by checking whether the desired value lies between A[i*][0]
and A[i*][m]
if A[i*][0] < x
on an increasing 2d array (each given line's elements are bigger than the previous').
The complexity should be log(n)+log(m) = log(nm)
.