The most efficient way to select the point with the closest points

NB: there is a major change at the bottom of the question - check

Question

Let's say I have a set of points:

Points

I want to find the point with the largest number of points surrounding it, in the radius R(i.e. the circle) or inside + -R(i.e. the square) of the point for two dimensions. I will call it the densest point function.

For the diagrams in this question, I will represent the surrounding region as circles. In the image above, the surrounding midpoint area is displayed in green. This midpoint has the closest points of all points in the radius Rand will be returned by the densest point function.

What i tried

; "O (log (n) + k) ". , , , .

, ( ), :

enter image description here

(1e6) . O (log (n) + k), k - , , :

  • kd- ( , O (sqrt (n) + k)),
  • ,
  • Quadtrees, O (n)

, 1e6 R O (log (1e6) + 1e6) . !

, ( O (n log (n)) )?

, ! .

(-)

:

  • O (log ^ d (n) + k), k ,
  • ( ) O (log ^ (d-1) (n) + k),
  • , O (log (n) + k),
  • , (.. ), O (log (n)).

, O (n log (n)), !

, 2d- .

( 113 ) , psedocode 2D-. , , , O(log n).

Java ++ , , , countInRange,

    * O (log (n) ^ d) . ,     * O (log (n) ^ d + k) , k - , .

, .

, , , - , O (log (n)), - , / ?

, - 2d O (log (n)) !

+6
3

. . ( , ):

  • Y- S.
  • 3 S: (C) () ; , A ( ) > R C; , B ( ) < R .
  • , A ( X) , B . , R / C , C.
  • " ".

, ( X-Y), . ( R-) - , ( 1 ). ( ) O (n log n).

( R , ), :

approximated circle

2 , / / . 3 (< = R), .

( ). ( , ):

  • , , , Y, X.
  • , "" 3.
  • , , R, , "" "". , , .
  • " ".

, .

+1

- https://en.wikipedia.org/wiki/K-d_tree, node . node , .

. node , R , R , R R. node R . , . .

, R, , .

, , kd, , , A x A, R , , O (A), , O (n) , , O (n * sqrt (n)).

+1

, , O(n) , .

R , R x y. , . c :

c.x<=p.x && p.x<=c.x+R && c.y<=p.y && p.y<=c.y+R

(, ).

/ , . /, -.

. :

Grid of radius R

. . 7-9 . , , , 8 .

, p (x, y), N[p] p R, Np[y][x] (x, y), N[p] :

N[p] = Np[y][x]+
       Np[y][x-1]+
       Np[y-1][x-1]+
       Np[y-1][x]+
       Np[y-1][x+1]+
       Np[y][x+1]+
       Np[y+1][x+1]+
       Np[y+1][x]+
       Np[y+1][x-1]

, , maxheap O(n) (, make_heap). , O (log n) , .

O (log n + k) ( ), , . best_found N[p].

. N[best_found], . .

, :

Grid of radius R / 2

(., , - , , FIFO). , .

, :

Example of counting adjacent overlay neighbors

, : , , . , , .

You could and should use a similar restrictive technique in conjunction with mcdowella answers ; however, his answer does not provide a good place to start the search, so you can spend a lot of time exploring items with low cost.

0
source

All Articles