Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First you need to find every element's nearest neighbor in the other set.</p> <p>To do this efficiently you need a <a href="http://en.wikipedia.org/wiki/Nearest_neighbor_search" rel="noreferrer">nearest neighbor</a> algorithm. Personally I would implement a <a href="http://en.wikipedia.org/wiki/Kd_tree" rel="noreferrer">kd-tree</a> just because I've done it in the past in my algorithm class and it was fairly straightforward. Another viable alternative is an <a href="http://en.wikipedia.org/wiki/R-tree" rel="noreferrer">R-tree</a>.</p> <p>Do this once for each element in the smallest set. (Add one element from the smallest to larger one and run the algorithm to find its nearest neighbor.)</p> <p>From this you should be able to get a list of nearest neighbors for each element.</p> <p>While finding the pairs of nearest neighbors, keep them in a sorted data structure which has a fast addition method and a fast getMax method, such as a <a href="http://en.wikipedia.org/wiki/Heap_(data_structure)" rel="noreferrer">heap</a>, sorted by <a href="http://en.wikipedia.org/wiki/Euclidean_distance" rel="noreferrer">Euclidean distance</a>.</p> <p>Then, once you're done simply ask the heap for the max.</p> <p>The run time for this breaks down as follows:</p> <p>N = size of smaller set<br /> M = size of the larger set</p> <ul> <li>N * O(log M + 1) for all the kd-tree nearest neighbor checks.</li> <li>N * O(1) for calculating the Euclidean distance before adding it to the heap.</li> <li>N * O(log N) for adding the pairs into the heap.</li> <li>O(1) to get the final answer :D</li> </ul> <p>So in the end the whole algorithm is O(N*log M).</p> <p>If you don't care about the order of each pair you can save a bit of time and space by only keeping the max found so far.</p> <p>*Disclaimer: This all assumes you won't be using an enormously high number of dimensions and that your elements follow a mostly random distribution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload