Here's what I would try. Given an m
by n
matrix A
, compare the value X
with the entry A(m/2,n/2)
(use floors if necessary).
If A(m/2,n/2) == X
, done.
If A(m/2,n/2) < X
, then there are 3 smaller matrices to check:
A(1:m/2, 1:n/2)
A(1:m/2, n/2+1:n)
A(m/2+1:m, 1:n/2)
If A(m/2,n/2) > X
, , then there are 3 smaller matrices to check:
A(m/2:m, n/2:n)
A(1:m/2, n/2+1:n)
A(m/2+1:m, 1:n/2)
You can eliminate two of them (not always) by comparing the value to the smallest value in the corresponding matrix (the upper left value). Then you recursively try to find the value in each of the remaining matrices.
The complexity of this is approximately O((n*m)^0.8)
.
A row and column sorted matrix is a special case of a Young tableau. I did a google search for searching a Young tableau and found this article which gives 3 nice approaches (the first (and worst) of which is the one I described above).