Choosing the closest warehouse for an order is easy when there are five candidates: compute each distance and take the smallest. With thousands of stores and many orders, repeatedly checking every candidate becomes costly. A distance function supplies the value used to compare candidates; the search method determines how many such comparisons are needed. section 8.2
First identify what the function measures. For points, it compares a target with stored points. A nearest-neighbor query returns the closest point or N closest points; a distance threshold can instead define a spherical search region. Coordinates need not describe physical space: price and rating can form a two-dimensional point. The nearest-neighbor structures described here require Euclidean distance for these dimensions. section 8.3
A distance function is also a structural choice in an SS-tree. To decide whether a point may lie in a node’s bounding sphere, compare its distance from the sphere’s centroid with the radius. This distance can be Euclidean or another valid metric: it must be non-negative, zero only for a point compared with itself, symmetric, and satisfy the triangle inequality. section 10.3.1
Listing 10.4 Method SsNode::intersectsPoint
function SsNode:: intersectsPoint(point) #1 return distance(this.centroid, point) <= this.radius #2
The sphere-intersection test reduces to one distance calculation and a comparison with the node’s radius. section 10.3.1
Distance thresholds in canopy clustering
Select a point p as a canopy center and compute distance(p, q) for each point q. If the value is below T1, add q to the canopy; if it is also below the smaller threshold T2, remove q as a possible future center. A faster approximate distance metric can reduce work, at the cost of a less precise preliminary grouping that a later clustering algorithm can refine. section 13.1.3
For graph paths, the argument changes from a pair of points to an edge. A* accepts distance(e) as the contribution to the cost of reaching the next vertex; its heuristic separately estimates the remaining cost to the goal. Choosing distance(e) = e.weight and a zero heuristic gives Dijkstra’s behavior. Choosing distance(e) = 1 and a zero heuristic counts edges, as breadth-first search does. Here, “distance” means a path-cost contribution, not necessarily a geometric metric. section 14.5









