Skip to content

Resource · Guide or article

Levenshtein Distance

Teaches minimum edit distance (insertions, deletions and substitutions) and how to compute it with a bottom-up dynamic programming table. A good fit before interviews that include classic string DP problems.

Reviewed

Open the original: Levenshtein Distance (opens the original site in a new tab)

Practice this topicOpens the practice interviewer in Technical / coding mode; choose a question there.

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

The Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. Mathematically, the Levenshtein distance between two strings a and b (of length |a| and |b| respectively) is given by where where is the indicator function equal to 0 when and equal to 1 otherwise, and is the distance between the first i characters of a and the first j characters of b.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Lesson

What it covers

  • Gives the recursive mathematical definition, shown as formula images
  • Works the kitten to sitting example, which needs three edits
  • Reads a 3x3 matrix for ME to MY cell by cell, separating deletions from insertions
  • Explains that each cell depends on three neighbors and names the tabulation technique
  • Shows a decision graph with overlapping subproblems and a larger Saturday to Sunday matrix

How to use it

PrepKit study advice, not a claim made by the source.

Fill the Saturday to Sunday table on paper before looking at the image, then code it and check the result. Afterward, explain aloud what each of the three neighbor cells represents.

Scope and limitations

Key formulas and matrices are external images, so the text alone is hard to follow when they fail to load. No complexity figures are given, and there are no exercises beyond the worked examples.

Access and format

README on GitHub in trekhleb/javascript-algorithms (MIT), with images hosted elsewhere. English, free.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/string/levenshtein-distance/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email