I assume you want something like this. You have a matrix like
1100101 1110101 0100101
You need columns 1,2,5,7 and rows 1 and 2, right? This sub-matrix will be 4x2 with 8 elements. Or you could go with columns 1,5,7 with rows 1,2,3, which would be a 3x3 matrix.
If you need an approximate method, you can start with one non-zero element, and then continue searching for another non-zero element and add it to the list of rows and columns. At some point, you will come across a non-zero element that, if rows and columns were added to your collection, your collection would no longer be completely non-zero.
So, for the above matrix, if you added 1,1 and 2,2, you will have rows 1,2 and columns 1,2 in your collection. If you tried adding 3.7, this will cause a problem because the value of 1.3 is zero. Therefore, you could not add it. You could add 2.5 and 2.7. Creating a 4x2 sub-matrix.
Basically, you will iterate until you can find new new rows and columns to add. This would give you a local minimum. You can save the result and start again from a different starting point (perhaps one that did not fit into your current solution).
Then just stop when after a while you cannot find more.
This will obviously take a lot of time, but I don’t know if you can do it faster.
Chad okere
source share