Assume that I have a set of rectangles (with different or same dimensions).
- The task is to find (and remove) the rectangle from the set that is larger or equal to a given rectangle.
- It should also be the smallest rectangle in the set than can encompass the given rectangle.
This is easily solved in O(n) time by doing a linear search / update, but is it possible to achieve better results? O(log n) would be optimal I'd assume. Insert and removal must also be faster than O(n) for this to be of any use in my case.
Can any shortcuts be made by not finding the optimal rectangle, but rather relax the 2nd restriction to: "It should also be one of the smallest rectangles that can encompass the given rectangle"-
I was thinking along the lines of using a Z-order curve (of the width/height) and use as a one dimensional index and combine that with a tree. Would that work? Or would there be too much waste?
Another approach would be to use tree using one axis, and then test the other linearly.
Anyone done something similar and can share their experience?