Given a matrix of size mxn containing 0\'s and 1\'s only. I need to find the largest sub-matrix which has equal number of 1\'s and 0\'s in it. Brute force appro
I assume a submatrice is formed using only contiguous rows\columns of the original matrix (ie by removing first\last row or columns).
This way, a matrix can be represented as
Mat = {origin(row,col), rowCount, columnCount}
If the original matrix is of dimension M x N, then
rowCount = M - row
columnCount = N - col
Mat = {origin(row,col), M - row, N - col}.
The variable row and col has respectively M and N possible values, which means
there are O(MxN) of such matrices.
Idea of Algorithm
(m, n)from queue(m, n-1) and (m-1, n) and put on queueNow there are two points:
O(n) or O(m) time. this is the dynamic programming step.Which mean the complexity is O(max(M,N)MN)