Re: Covering rectangles in 2D
- From: quasi <quasi@xxxxxxxx>
- Date: Fri, 21 Mar 2008 21:01:47 -0500
On Tue, 18 Mar 2008 03:18:04 -0000, Tim Little
<tim@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On 2008-03-17, quasi <quasi@xxxxxxxx> wrote:
I'm not sure what this means. If you are visiting every cell formed by
the grid lines, that O(N^2), right there
Yes, that's where the O(N^2) comes from.
Does passing a grid line means you are sweeping down a column, or
does it mean you have finished sweeping across the row above and are
proceeding to the next row?
Either/both. It just means crossing from one cell of the grid to a
neighbouring cell.
Also, a grid line is not, in general, an edge of a rectangle, so I
don't know what you mean by "check whether it was a real edge".
Each of the (unevenly spaced) grid lines is generated by a rectangle
that has a side aligned along that X or Y coordinate. In general
there are up to 4 of these, 2 vertical and 2 horizontal.
Each transition from one grid cell to a neighbouring one crosses a
grid line, hence is associated with a rectangle (or list of
rectangles, but we can treat this much like a sequence of grid lines
with 0 separation).
So all we need do is check that rectangle to see whether the
transition enters or leaves that rectangle.
If it was real, increment or decrement the count of currently
overlapping rectangles.
I don't follow.
As we sweep through the grid, we keep a count of how many rectangles
are covering the cell we're looking at. Passing a grid line can
change that count by -1, 0, or +1. Checking which is an O(1)
operation.
You might be right -- maybe it's O(N*log N), but I'm not convinced.
Nor am I. O(N log N) might be a bit ambitious, but perhaps O(N^1.5)
is achievable.
I don't really understand your algorithm, but from what I can follow,
I don't think you achieved O(N^2). There are O(N^2) cells, right? And
it appears your method visits all of them, one at a time. Of course
that's at least O(N^2) right there, but when you visit a cell,
checking whether or not that cell is occupied is not O(1). Checking a
cell is at most O(N), so for the full grid, O(N^3) is the worst case.
With some pre-sorting of the rectangles, perhaps you can get less than
O(N^3), but I don't see O(N^2), not from what you described.
quasi
.
- Follow-Ups:
- Re: Covering rectangles in 2D
- From: Tim Little
- Re: Covering rectangles in 2D
- References:
- Covering rectangles in 2D
- From: Hector
- Re: Covering rectangles in 2D
- From: Tim Little
- Re: Covering rectangles in 2D
- From: quasi
- Re: Covering rectangles in 2D
- From: Tim Little
- Re: Covering rectangles in 2D
- From: quasi
- Re: Covering rectangles in 2D
- From: Tim Little
- Covering rectangles in 2D
- Prev by Date: Re: the shortest and longest Good Fridays
- Next by Date: Re: Islam prohibits coitus during menstruation
- Previous by thread: Re: Covering rectangles in 2D
- Next by thread: Re: Covering rectangles in 2D
- Index(es):
Relevant Pages
|