# Well-separated pair decomposition

In computational geometry, a well-separated pair decomposition (WSPD) of a set of points $S\subset \mathbb {R} ^{d}$, is a sequence of pairs of sets $(A_{i},B_{i})$, such that each pair is well-separated, and for each two distinct points $p,q\in S$, there exists precisely one pair which separates the two.
The graph induced by a well-separated pair decomposition can serve as a k-spanner of the complete Euclidean graph, and is useful in approximating solutions to several problems pertaining to this.

## Definition

Let $A,B$ be two disjoint sets of points in $\mathbb {R} ^{d}$, $R(X)$ denote the axis-aligned minimum bounding box for the points in $X$, and $s>0$ denote the separation factor.
We consider $A$ and $B$ to be well-separated, if for each of $R(A)$ and $R(B)$ there exists a d-ball of radius $\rho$ containing it, such that the two spheres have a minimum distance of at least $s\rho$.
We consider a sequence of well-separated pairs of subsets of $S$, $(A_{1},B_{1}),(A_{2},B_{2}),\ldots ,(A_{m},B_{m})$ to be a well-separated pair decomposition (WSPD) of $S$ if for any two distinct points $p,q\in S$, there exists precisely one $i$, $1\leq i\leq m$, such that either
* $p\in A_{i}$ and $q\in B_{i}$, or
* $q\in A_{i}$ and $p\in B_{i}$.

## Construction
### Split tree

By way of constructing a fair split tree, it is possible to construct a WSPD of size $O(s^{d}n)$ in $O(n\lg n)$ time.
The general principle of the split tree of a point set S is that each node u of the tree represents a set of points S$_u$ and that the bounding box R(S$_u$) of S$_u$ is split along its longest side in two equal parts which form the two children of u and their point set. It is done recursively until there is only one point in the set.
Let L$_{max}$(R(X)) denote the size of the longest interval of the bounding hyperrectangle of point set X and let L$_i$(R(X)) denote the size of the i-th dimension of the bounding hyperrectangle of point set X. We give pseudocode for the Split tree computation below.
This algorithm runs in $O(n^{2})$ time.
We give a more efficient algorithm that runs in $O(n\lg n)$ time below. The goal is to loop over the list in only $O(n)$ operations per step of the recursion but only call the recursion on at most half the points each time.
Let S$_i$$^j$ be the i-th coordinate of the j-th point in S such that S$_i$ is sorted according to the i-th coordinate and p(S$_i$$^j$) be the point. Also, let h(R(S)) be the hyperplane that splits the longest side of R(S) in two. Here is the algorithm in pseudo-code:
To be able to maintain the sorted lists for each node, linked lists are used. Cross-pointers are kept for each list to the others to be able to retrieve a point in constant time. In the algorithm above, in each iteration of the loop, a call to the recursion is done. In reality, to be able to reconstruct the list without the overhead of resorting the points, it is necessary to rebuild the sorted lists once all points have been assigned to their nodes. To do the rebuilding, walk along each list for each dimension, add each point to the corresponding list of its nodes, and add cross-pointers in the original list to be able to add the cross-pointers for the new lists. Finally, call the recursion on each node and his set.

### WSPD computation

The WSPD can be extracted from such a split tree by calling the recursive FindPairs(v,w) function on the children of every node in the split tree. Let u$_l$ / u$_r$ denote the children of the node u. We give pseudocode for the FindWSPD(T, s) function below.
We give pseudocode for the FindPairs(v, w) function below.
Combining the s-well-separated pairs from all the calls of FindPairs(v,w) gives the WSPD for separation s.
Each time the recursion tree split in two, there is one more pair added to the decomposition. So, the algorithm run-time is in the number of pairs in the final decomposition.
Callahan and Kosaraju proved that this algorithm finds a Well-separated pair decomposition (WSPD) of size $O(s^{d}n)$.

## Properties

Lemma 1: Let $\{A,B\}$ be a well-separated pair with respect to $s$. Let $p,p'\in A$ and $q\in B$. Then, $|pp'|\leq (2/s)|pq|$.
Proof: Because $p$ and $p'$ are in the same set, we have that $|pp'|\leq 2\rho$ where $\rho$ is the radius of the enclosing circle of $A$ and $B$. Because $p$ and $q$ are in two well-separated sets, we have that $|pq|\geq s\rho$. We obtain that:
${\begin{aligned}&{\frac {|pp'|}{2}}\leq \rho \leq {\frac {|pq|}{s}}\\\Leftrightarrow &\\&{\frac {|pp'|}{2}}\leq {\frac {|pq|}{s}}\\\Leftrightarrow &\\&|pp'|\leq {\frac {2}{s}}|pq|\\\end{aligned}}$
Lemma 2: Let $\{A,B\}$ be a well-separated pair with respect to $s$. Let $p,p'\in A$ and $q,q'\in B$. Then, $|p'q'|\leq (1+4/s)|pq|$.
Proof: By the triangle inequality, we have:
$|p'q'|\leq |p'p|+|pq|+|qq'|$
From Lemma 1, we obtain:
${\begin{aligned}|p'q'|&\leq (2/s)|pq|+|pq|+(2/s)|pq|\\&=(1+4/s)|pq|\end{aligned}}$

## Applications

The well-separated pair decomposition has application in solving a number of problems. WSPD can be used to:
* Solve the closest pair problem in $O(n\lg n)$ time.
* Solve the k-closest pairs problem in $O(n\lg n+k)$ time.
* Solve the k-closest pair problem in $O(n\lg n)$ time.
* Solve the all-nearest neighbors problem in $O(n\lg n)$ time.
* Provide a $(1-\epsilon )$-approximation of the diameter of a point set in $O(n\lg n)$ time.
* Directly induce a t-spanner of a point set.
* Provide a t-approximation of the Euclidean minimum spanning tree in d dimensions in $O(n\lg n)$ time.
* Provide a $(1+\epsilon )$-approximation of the Euclidean minimum spanning tree in d dimensions in $O(n\lg n+(\epsilon ^{-2}\lg ^{2}{\frac {1}{\epsilon }})n)$ time.