Apex › Storage & databases

How fuzzy search finds typos (BK-tree)

How a spell-checker finds dictionary words within a small edit distance of a typo without scanning the whole dictionary. A BK-tree keys each edge by the edit distance between a word and its parent; because edit distance obeys the triangle inequality, a match within k of the query must lie within [d−k, d+k] of any node at distance d — so most subtrees are provably too far and get pruned. Real BK-tree, verified: the same matches as a brute-force scan, far fewer comparisons. Pick a query and watch branches grey out unseen.

More in Storage & databases