Hamming distance

Hamming distance
3-bit binary cube for finding Hamming distance
Two example distances: 100->011 has distance 3 (red path); 010->111 has distance 2 (blue path)
4-bit binary tesseract for finding Hamming distance
Two example distances: 0100->1001 has distance 3 (red path); 0110->1110 has distance 1 (blue path)

In information theory, the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. Put another way, it measures the minimum number of substitutions required to change one string into the other, or the number of errors that transformed one string into the other.

Contents

Examples

The Hamming distance between:

  • "toned" and "roses" is 3.
  • 1011101 and 1001001 is 2.
  • 2173896 and 2233796 is 3.

Special properties

For a fixed length n, the Hamming distance is a metric on the vector space of the words of that length, as it obviously fulfills the conditions of non-negativity, identity of indiscernibles and symmetry, and it can be shown easily by complete induction that it satisfies the triangle inequality as well. The Hamming distance between two words a and b can also be seen as the Hamming weight of ab for 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 Rn 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.

History and applications

The Hamming distance is named after Richard Hamming, who introduced it in his fundamental paper on Hamming codes Error detecting and error correcting codes in 1950.[1] It is used in telecommunication to count the number of flipped bits in a fixed-length binary word as an estimate of error, and therefore is sometimes called the signal 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 distance is more appropriate. For q-ary strings over an alphabet of size q ≥ 2 the Hamming distance is applied in case of orthogonal modulation, while the Lee distance is used for phase modulation. If q = 2 or q = 3 both distances coincide.

The Hamming distance is also used in systematics as a measure of genetic distance.[2]

On a grid (such as a chessboard), the points at a Lee distance of 1 constitute the von Neumann neighborhood of that point.

Algorithm example

The Python function hamming_distance() computes the Hamming distance between two strings (or other iterable objects) of equal length, by creating a sequence of zero and one values indicating mismatches and matches between corresponding positions in the two inputs, and then summing the sequence.

def hamming_distance(s1, s2):
    assert len(s1) == len(s2)
    return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))

The following C function will compute the Hamming distance of two integers (considered as binary values, that is, as sequences of bits). The running time of this procedure is proportional to the Hamming distance rather than to the number of bits in the inputs. It computes the bitwise exclusive or of the two inputs, and then finds the Hamming weight of the result (the number of nonzero bits) using an algorithm of Wegner (1960) that repeatedly finds and clears the lowest-order nonzero bit.

unsigned hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}

See also

Notes

References

External links

  • Hamming Code Tool Tool to generate hamming code
  • set_matcher Tool to match two families of sets from the same base population using Hamming distance.

Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Distance De Levenshtein — La distance de Levenshtein mesure la similarité entre deux chaînes de caractères. Elle est égale au nombre minimal de caractères qu il faut supprimer, insérer ou remplacer pour passer d’une chaîne à l’autre. Son nom provient de Vladimir… …   Wikipédia en Français

  • Distance de levenshtein — La distance de Levenshtein mesure la similarité entre deux chaînes de caractères. Elle est égale au nombre minimal de caractères qu il faut supprimer, insérer ou remplacer pour passer d’une chaîne à l’autre. Son nom provient de Vladimir… …   Wikipédia en Français

  • Hamming(7,4) — is a Hamming code that encodes 4 bits of data into 7 bits by adding 3 parity bits.Today, Hamming code really refers to a specific (7,4) code Richard W. Hamming introduced in 1950. The code stemmed from his work as a theorist at Bell Telephone… …   Wikipedia

  • Hamming code — In telecommunication, a Hamming code is a linear error correcting code named after its inventor, Richard Hamming. Hamming codes can detect and correct single bit errors. In other words, the Hamming distance between the transmitted and received… …   Wikipedia

  • Hamming — Richard Hamming Richard Hamming Nom de naissance Richard Wesley Hamming Naissance 11 février 1915 Chicago (Illinois) Décès 7 janvier 1998 (à 72 ans) Monterey (Californie) Nationalité …   Wikipédia en Français

  • Distance de Levenshtein — La distance de Levenshtein mesure la similarité entre deux chaînes de caractères. Elle est égale au nombre minimal de caractères qu il faut supprimer, insérer ou remplacer pour passer d’une chaîne à l’autre. Son nom provient de Vladimir… …   Wikipédia en Français

  • Hamming bound — In mathematics and computer science, in the field of coding theory, the Hamming bound is a limit on the parameters of an arbitrary block code: it is also known as the sphere packing bound or the volume bound from an interpretation in terms of… …   Wikipedia

  • Distance — This article is about distance in the mathematical or physical sense. For other senses of the term, see distance (disambiguation). Proximity redirects here. For the 2001 film, see Proximity (film). Distance (or farness) is a numerical description …   Wikipedia

  • Hamming weight — The Hamming weight of a string is the number of symbols that are different from the zero symbol of the alphabet used. It is thus equivalent to the Hamming distance from the all zero string of the same length. For the most typical case, a string… …   Wikipedia

  • Hamming space — In statistics and coding theory, a Hamming space is the set of all 2^N binary strings of length N. It is used in the theory of coding signals and transmission. Hamming codes and Hamming distance are related concepts.External links …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”