Hamming Distance
The Hamming distance is the number of positions at which corresponding characters differ between two equal-length strings; it only applies to equal-length comparisons.
Purpose
Measures the number of differing positions between equal-length strings, used in error detection and coding theory.
Mechanism
For equal-length strings s and t, d = Σ(s[i] ≠ t[i]). Defined only when lengths are equal. For binary strings the Hamming distance can be computed efficiently with bitwise operations (XOR + popcount).
Use cases
- Error detection and error-correcting codes
- Binary string similarity
- Perceptual difference of image hashes
- Information theory education
Examples
- Input
karolin → kathrinOutput33 positions differ
Common errors
- Applying the Hamming distance to strings of unequal length
- Use the Levenshtein distance for variable lengths
Related terms
Levenshtein Distance
The Levenshtein distance is the minimum number of single-character insertions, deletions, and substitutions needed to make two strings identical. GLOSSARY
Jaro-Winkler Distance
The Jaro-Winkler distance is a refinement of the Jaro distance that weights common prefixes, making it better suited for matching short strings such as person names where prefixes matter. GLOSSARY
Edit Distance
Edit distance is the minimum number of single-character edit operations (insertion, deletion, substitution) required to transform one string into another; the Levenshtein distance is its most common form. GLOSSARY