TOPICS
Search

Hamming Distance


The Hamming distance between two strings of equal length is the number of positions at which their symbols differ (Black 2006). For binary strings, this is the number of coordinates at which the corresponding vertices of a hypercube graph differ. For example, abc and bca have Hamming distance 3.

For binary strings x and y of length n,

 d_H(x,y)=w_H(x xor y),
(1)

where w_H is the Hamming weight and  xor denotes bitwise XOR. Indeed, a coordinate of x xor y is 1 iff the corresponding coordinates of x and y differ. For any binary string k of length n, applying the same XOR mask to both arguments gives

 d_H(x xor k,y xor k)=d_H(x,y).
(2)

Thus common XOR masking is an isometry of the binary string space.

For a subset F subset= {0,1}^n with |F|=2^(n-3) and n>=3, Fang and Huang (2026) proved

 Ed_H(X,Y)>=(n-3)/2,
(3)

where X and Y are independent uniform elements of F, so equal pairs are included. Equality holds precisely when F is a codimension-three subcube, obtained by fixing three coordinates. Fang and Huang (2026) report that discussions with ChatGPT led to the trigonometric polynomials in Lemma 2.3.


See also

Edit Distance, Hamming Code, Hamming Graph, Hamming Weight, Hypercube, String, XOR

Explore with Wolfram|Alpha

References

Black, P. E. "Hamming Distance." In Dictionary of Algorithms and Data Structures (Ed. P. E. Black). National Institute of Standards and Technology, May 31, 2006. https://xlinux.nist.gov/dads/HTML/HammingDistance.html.Exoo, G. "A Euclidean Ramsey Problem." Disc. Comput. Geom. 29, 223-227, 2003. https://doi.org/10.1007/s00454-002-0780-5.Fang, Y. and Huang, H. "Average Pairwise Hamming Distance of a Subset in a Hypercube." 29 Oct 2026. https://arxiv.org/abs/2610.40486.

Referenced on Wolfram|Alpha

Hamming Distance

Cite this as:

Weisstein, Eric W. "Hamming Distance." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/HammingDistance.html

Subject classifications