Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding hamming distance of code

A question asks: find the hamming distance of the following code:

11111  
10101  
01010  
11100  
00011  
11001

The answer is 2. How does this work? I thought hamming distance is only between two strings?

like image 816
Celeritas Avatar asked Oct 05 '12 07:10

Celeritas


People also ask

What is the Hamming distance between 0101 0101 and 1010 1010?

Since the two codewords differ in 6 bit positions as indicated by bold letter bits, the hamming distance is 6.

What is the Hamming distance of bit strings 10101 and 11110?

The Hamming distance d(10101, 11110) is 3 because 10101 ⊕ 11110 is 01011 (three 1s).

What is the Hamming distance between 10101010 and 10011100?

Answer. Now, 10101010 ⊕ 10010010 = 111000. Since there are three zeroes, the hamming distance is 1 + 1 + 1 = 3.

What is the Hamming distance between 001111 and 010011?

The correct answer should be 3. In information technology studies, the Hamming distance in between two strings which are of equal length is defined by the number of positions at which their corresponding symbols are different.


2 Answers

The Hamming distance of a code is defined as the minimum distance between any 2 codewords. So, in your case, finding the Hamming distance between any 2 of the listed codewords, no one is less than 2.

like image 183
guga Avatar answered Oct 12 '22 22:10

guga


Here is some Python-code to find it automatically:

code = [
(0,0,0,0,0,0),
(0,0,1,0,0,1),
(0,1,0,0,1,0),
(0,1,1,0,1,1),
(1,0,0,1,0,0),
(1,0,1,1,0,1),
(1,1,0,1,1,0),
(1,1,1,1,1,1)]

def hammingDistance(a, b):
    distance = 0
    for i in xrange(len(a)):
        distance += a[i]^b[i]
    return distance

def minHammingDistance(code):
    minHammingDistance = len(code[0])
    for a in code:
        for b in code:
            if a != b:
                tmp = hammingDistance(a, b)
                if tmp < minHammingDistance:
                    minHammingDistance = tmp
    return minHammingDistance

print("min Hamming distance: %i" % minHammingDistance(code))
like image 28
Martin Thoma Avatar answered Oct 12 '22 23:10

Martin Thoma