Learn: Hamming Distance in Javascript
Hamming’s distance takes its name from Richard Hamming, who introduced it in his work on error recognition and correction codes. It is used in telecommunications to count the number of erroneous bits in a fixed-length binary word in order to estimate the error. For this reason it is also called signal distance. Hamming weight analysis of bits is used in several disciplines, including information theory, code theory and cryptography.
The limit of the Hamming Distance is the fact that this theory is applicable only for string with the same length, in fact the algorithm is very simple to be implemented.
The Hamming distance between two equal-length strings of symbols is the number of positions at which the corresponding symbols are different.
In other words, the Hamming distance measures the number of substitutions necessary to convert one string into another, or, seen in another way, the minimum number of errors that may have led to the transformation of one string into another.
Examples
- “karolin” and “kathrin” is 3.
- “karolin” and “kerstin” is 3.
- “kathrin” and “kerstin” is 4.
- 0000 and 1111 is 4.