liveBook · Manning

Edit distance

As explained in Clojure: The Essential Reference

Levenshtein distance is a metric counting the minimum single-character insertions, deletions, or substitutions needed to transform one string into another.

Edit distance measures the difference between two strings by counting the minimum single-character insertions, deletions, or substitutions needed to transform one into the other. It is useful for spelling correction, where smaller distances indicate better candidates. section 2.4.2

A practical autocorrection workflow:

  • Compare the misspelled input with dictionary words. section 2.4.2

Memoized spelling suggestions

A recursive Clojure implementation handles empty strings directly and considers insertion, deletion, and substitution. Memoizing it avoids recomputing identical string pairs. For "achive", the best candidates include ["achieve" 1], ["achime" 1], and ["active" 1].

How Clojure: The Essential Reference covers it

How deep it goes
Defines the metric and demonstrates a recursive implementation with empty-string cases, then optimizes repeated calls through memoization.
Examples
Uses the misspelled word "achive" and dictionary candidates such as "achieve", "achime", and "active".
What you can do after
Apply it via a memoized Clojure function to rank likely spelling corrections efficiently.
How it connects
Connects edit distance with memoization, recursion, dictionary filtering, and spelling correction.

Also explained in

Compare how 6 books explain edit distance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.