10-605 · Randomized algorithms 2 · k-NN search
Cluster the N points into J clusters, then run J-means again inside each cluster, down to depth d. To search for a query qx, find the centroid closest to qx among its J siblings at each level (O(dJ) distance computations), then scan only the points in that leaf (O(N/Jd)). Click or drag anywhere on the plot to move qx.
The path through the tree is a compact code for qx: its leaf centroid is an approximate encoding of qx, like an LSH signature.
| N | J | d | k | avg leaf size | distance comps | vs. N | recall@k |
|---|
Each run draws 300 queries from the same distribution as the data and adds one row, so you can compare settings. "distance comps" is dJ + |leaf| per query, averaged.
Build(points, depth): if depth = 0: return a leaf holding points run J-means on points → centroids c1,…,cJ, clusters C1,…,CJ childi = Build(Ci, depth − 1) for i = 1,…,J Search(qx, k): node = root while node is not a leaf: O(J) per level, d levels i = argmini dist(qx, ci) over node's children node = childi return the k points x in node closest to qx O(N/Jd)