core practice · coding problem
Distances concentrate as dimensions grow
Implement contrast(points, query) returning (maxDist - minDist) / minDist using Euclidean distance — the relative contrast between the farthest and nearest point. Round to 3 decimals. Return 0 when minDist is 0.
The mechanism
As dimensions grow, the distance from a query to its nearest and farthest points converges: the ratio (max−min)/min tends to zero, so 'nearest' stops being meaningful and an index that prunes by distance has nothing left to prune with. This is why exact high-dimensional search degrades to a scan and why ANN methods change the question — they exploit the fact that real embeddings occupy a low-dimensional manifold rather than filling the space uniformly.
Expected evidence
Contrast is large in low dimensions and tends toward 0 as dimensionality grows.
Try this drill in the practice workspace →
Hints when you need them
- Plain Euclidean distance; the interesting part is what the ratio does as the vectors get longer.
- Guard the zero-distance case before dividing.
Watch for these mistakes
- Assuming intuition from 2D or 3D survives — volume concentrates near the shell of a high-dimensional ball, not the centre
- Concluding nearest-neighbour search is hopeless; the theory assumes independent uniform data, and real embeddings are far from that
- Adding dimensions to an embedding expecting monotonically better retrieval
- Comparing raw Euclidean distances across dimensionalities as if the scale were the same