In information theory, the Hamming distancebetween two stringsof equal length is the number of positions at which the corresponding symbols are different. Put another way, it measures the minimum number of substitutionsrequired to change one string into the other, or the number oferrorsthat transformed one string into the other.
2173896and 2233796 is 3. “2173896”和“2233796”的海明距离是3.
For a fixed length n, the Hamming distance is a metricon the vector space of the words of length n, as it obviously fulfills the conditions of non-negativity, identity of indiscernibles and symmetry, and it can be shown easily by complete inductionthat it satisfies the triangle inequalityas well. The Hamming distance between two words aand bcan also be seen as the Hamming weightof a−bfor an appropriate choice of the − operator.
For binary strings a and b the Hamming distance is equal to the number of ones (population count) in a XOR b. The metric space of length-n binary strings, with the Hamming distance, is known as the Hamming cube; it is equivalent as a metric space to the set of distances between vertices in a hypercube graph. One can also view a binary string of length n as a vector in
by treating each symbol in the string as a real coordinate; with this embedding, the strings form the vertices of an n-dimensional hypercube, and the Hamming distance of the strings is equivalent to the Manhattan distance between the vertices.
The Hamming distance is named after Richard Hamming, who introduced it in his fundamental paper onHamming codesError detecting and error correcting codesin 1950.[1]It is used intelecommunicationto count the number of flipped bits in a fixed-length binary word as an estimate of error, and therefore is sometimes called thesignal distance. Hamming weight analysis of bits is used in several disciplines including information theory, coding theory, and cryptography. However, for comparing strings of different lengths, or strings where not just substitutions but also insertions or deletions have to be expected, a more sophisticated metric like the Levenshtein distanceis more appropriate. For q-ary strings over an alphabetof size q≥ 2 the Hamming distance is applied in case of orthogonal modulation, while the Lee distanceis used for phase modulation. If q= 2 or q= 3 both distances coincide.
The Hamming distance is also used in systematicsas a measure of genetic distance.[2]