Smallest variation of the point algorithm

I know this may be a duplicate, but it looks like a variant of the algorithm "The closest pair of points."

Given the set of N points (x, y) in a unit square and the distance d, find the whole pair of points, so that the distance between them is at most d.

For large N, brute force is not an option. In addition to the “sweep” and “division and subjugation” methods, is there a simpler solution? These pairs of points are the edges of an undirected graph, so I need to go through it and say whether it is connected or not (which I already did using DFS, but when N = 1 million it never ends!).

Any pseudo codes, comments or ideas are welcome, thanks!

EDIT: I found this in the Sedgewick book (I am looking at the code now):

Program 3.18 uses a two-dimensional array of linked lists to improve the running time of program 3.7 by about 1 / d2 when N is large enough. It divides the block square up into a grid of smaller squares of equal size. Then for each square he builds a linked list of all who fall into this square. A two-dimensional array provides immediate access to many points close to a given point; linked lists provide the flexibility to store points where they can fall without our knowing in advance how many points fall in each square of the grid.

+5
source share
2 answers

We are really looking for points inside the circle of the center (x, y) and radius d.

, , (x, y) 2d. , . , a (xa, ya) , abs (xa-x) > d abs (ya -yb) > d.

, , (x, y) 2d. , . , a (xa, ya) , abs (xa - x) < (d * 1,412) (ya-yb) (d * 1.412).

, . x, , y, , , .

+2

(x-delta plus y-delta), , "d", - , (sqrt (2) * d), .

0

All Articles