- Related Questions & Answers
- Hamming Distance in Python
- Total Hamming Distance in C++
- Hamming Distance between two strings in JavaScript
- Error Correcting Codes - Hamming codes
- Edit Distance
- Hamming code for single error correction, double error detection
- Count paths with distance equal to Manhattan distance in C++
- Minkowski distance in Python
- Edit Distance in C++
- Levenshtein Distance in JavaScript
- Place k elements such that minimum distance is maximized in C++
- Distance between Vertices and Eccentricity
- Connectivity, Distance, and Spanning Trees
- One Edit Distance in C++
- Pick points from array such that minimum distance is maximized in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Hamming distance is a metric for comparing two binary data strings. While comparing two binary strings of equal length, Hamming distance is the number of bit positions in which the two bits are different.

The Hamming distance between two strings, a and b is denoted as d(a,b).

It is used for error detection or error correction when data is transmitted over computer networks. It is also using in coding theory for comparing equal length data words.

In order to calculate the Hamming distance between two strings, and , we perform their XOR operation, (a⊕ b), and then count the total number of 1s in the resultant string.

Suppose there are two strings 1101 1001 and 1001 1101.

11011001 ⊕ 10011101 = 01000100. Since, this contains two 1s, the Hamming distance, d(11011001, 10011101) = 2.

In a set of strings of equal lengths, the minimum Hamming distance is the smallest Hamming distance between all possible pairs of strings in that set.

Suppose there are four strings 010, 011, 101 and 111.

010 ⊕ 011 = 001, d(010, 011) = 1.

010 ⊕ 101 = 111, d(010, 101) = 3.

010 ⊕ 111 = 101, d(010, 111) = 2.

011 ⊕ 101 = 110, d(011, 101) = 2.

011 ⊕ 111 = 100, d(011, 111) = 1.

101 ⊕ 111 = 010, d(011, 111) = 1.

Hence, the Minimum Hamming Distance, *d _{min}* = 1.

Advertisements