# Given a vector of points, what is the fastest algorithm to find all pairs of points at a distance of 1?

Given a vector of points (on the 2D plane), what is the fastest algorithm to find all pairs of points at a distance of 1?

Of course, I could use the $$O(N^2)$$ algorithm to check all pairs of points. However, I recently found out that there are at most $$O(N^{4/3})$$ points which satisfy the property, so I am wondering if a quicker algorithm exists.

Thanks!

You may use a Well-Separated Pairs Decomposition (WSPD). This is a hierarchical decomposition, where at each level, you split the points into two parts, each of them a certain distance from the sphere enclosing the other set, and a certain radius of the sphere containing them.

It runs in $$O(n\log n + X)$$, where $$X$$ is an output sensitive parameter, that measures the number of the partitions required to make the full decomposition. (Of course, you can stop the decomposition algorithm after you are working with distances less than 1)

• This reduces the problem to the bipartite case but it is not clear how to enumerate unit distance pairs in a decomposition set pair $(A_i, B_i)$. Could you clarify it? Jan 19, 2022 at 5:45
• You run the same procedure recursively. Jan 19, 2022 at 6:17
• For example, let the point set be $A \cup B$ where $A = \{ 0 + \epsilon_i \}_{i=1}^{n/2}, B = \{ 1 + \epsilon_i \}_{i=n/2+1}^n$, $0 < \epsilon_i \ll 1 \; \forall i$. The WSPD contains a pair $(A, B)$, but how to enumerate pairs $a \in A, b \in B, |a - b| = 1$ in $o(n^2)$ time? Jan 19, 2022 at 6:50

The problem can be regarded as a special case of incidence reporting problem with $$N$$ unit circles and $$N$$ points in the plane.

If the number of unit circles is $$m$$, then this problem can be solved in $$\tilde{O}(m^2 + N)$$ time ($$\tilde{O}(\cdot)$$ ignores polylogarithmic factors). First, explicitly computing the arrangement (the division of the plane, its edges, and vertices) of circles, then constructing a point location data structure, and query the data structure for each point.

The set of $$N$$ circles can be partitioned into $$\sqrt N$$ subsets of each $$\sqrt N$$ size, and each sub-problem can be solved separately. The total runtime is $$\tilde{O}(N^{3/2})$$. A more involved approach yields a $$\tilde{O}(N^{4/3})$$-time randomized algorithm [1].