1

Input: nxn matrix of postitive/negative numbers and k.

Output: submatrix with maximum sum of its elements divided by its number of elements that has at least k elements.

Is there any algorithm better than O(n^4) for this problem?

Mohammad Moghimi
  • 4,636
  • 14
  • 50
  • 76

2 Answers2

1

An FFT-based divide-and-conquer approach to this problem:

https://github.com/thearn/maximum-submatrix-sum

It's not as efficient as Kadane's, (O(N^3) vs. O(N^3 log N)) but does give a different take on solution construction.

thearn
  • 323
  • 3
  • 6
0

There is a O(n^3) 2-d kadane algorithm for finding the maximum sum submatrix (i.e. subrectangle) in an nxn matrix. (You can find posts on SO about it, or read online). Once you understand how the algorithm works, it is clear that you can get an O(n^3) time solution for your problem if you can solve the problem of finding a maximum average subinterval of length at least m in a 1-d array of n numbers in O(n) time. This is indeed possible, see the paper cs.slu.edu/~goldwasser/publications/DensityPreprint.pdf

Thus there is an O(n^3) time solution for your problem.

user2566092
  • 4,631
  • 15
  • 20