We have a rectangular grid with size NxM, in which each cell can be either free or occupied. Number or free cells is much bigger than number of occupied, thus we represent our grid as a list of XY coordinates of occupied cells. Also we assume that occupied cells have a certain structure.
We want to find a largest rectangle which covers only free cells. Next we want to find another largest rectangle which should not only cover only free cells, but also which should not overlap with previously found rectangles. We want to find all such rectangles up to a given threshold area.
In other words we want to find a rectangular tiling which covers maximum area of free cells using greedy algorithm.
Example:
Input grid (0
- free, x
- occupied):
0 0 0 0 0
0 0 0 0 0
x 0 x 0 0
0 0 x 0 0
0 0 0 0 0
Solution (cell numbers denote solution rectangles):
1 1 1 1 1
1 1 1 1 1
x 0 x 2 2
3 3 x 2 2
3 3 0 2 2
What algorithms can be used to computationally effectively solve this problem? On a first glance some kind of index (e.g. quadtree) should be utilized to get a practical performance for large M
and N
(e.g. hundreds of thousands). Solution does not have to be optimal, sub-optimal, but computationally efficient approaches, are good as well. Academic literature references are welcomed!
Bonus points: generalized approach applicable to 2D and 3D grids (and maybe even to higher dimensions as well).