1
$\begingroup$

Given $N$ circles and $Q$ points. What is the optimal solution for checking "if point is covered by any circle" for every point? The trivial solution would be $O(QN)$.

$\endgroup$
  • 1
    $\begingroup$ If all circles have the same ratio the problem can be solved online using some data structure that returns the closest circle center to the given point, and checking if the distance between them is less than the ratio. Such data structures are kd-trees, vantage-point and other spatial trees. $\endgroup$ – Marcelo Fornet Jan 9 '18 at 17:31
  • $\begingroup$ If circles intersection has zero area (i.e. at most share one point) the problem can be solved offline with complexity $O( (Q+N) log(Q+N) )$ If you are interested in this solution let me know and I explain it to you. $\endgroup$ – Marcelo Fornet Jan 9 '18 at 17:37
1
$\begingroup$

Let's suppose you have a spatial data structure that can be built over a set $S$ of points on the plane and expose the functions.

Build(S): Build and return the data structure storing all points in S
ds.Delete(q): Deletes point q from the set S
ds.Search(p): Return the closest point in S to point p

Now let's solve the problem backwards, instead of finding if a point is contained by some circle, lets find points for each circle the points it contains.

C: Set of circles
P: Set of points
ds := Build(P) # Build the data structure using points to be queried

for each circle c in C:
   do
      p = ds.Search(c.center)
      if p is inside circle c:
          ds.Delete(p)
   while (ds is not empty and one point was deleted)

All the deleted points from the data structure are the points that belongs to at least one circle, remaining points are not contained in any circle, otherwise they were being found when processing such circle.

Let $N:=|C|$ and $Q:=|P|$

The overall complexity of this algorithm is $$O(Build(Q) + (N + Q) \cdot Search(Q) + Q \cdot Delete(Q))$$

Here $Build(Q)$ is the complexity of building the set of $Q$ points, $Search(Q)$ is the complexity of searching for a point in a set of at most $Q$ points and $Delete(Q)$ is the complexity of deleting a point in a set of at most $Q$ points.

Notice that this cost is amortized, since after a point is recognized to be inside a circle it is deleted from the set.

One data structure that provides good balance for this operations is kd-tree, but I encourage you to find other spatial data structures that provides better complexity for your case.

$\endgroup$
  • $\begingroup$ this solution is pretty impressive, but it is my bad that I did not explained it well. 1. circles may have different radius. 2. circles may share same area. 3. points are not given at once. points are being queried one after another. $\endgroup$ – Eziz Durdyyev Jan 10 '18 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.