|
Let
be bit patterns, that is, vectors consisting of zeros and ones.
The Hamming distance $d_H(u,v)$ defined as$$ \sum_{j=1}^n |x_i-y_i|$$ is equal to the number of positions where the bit patterns are differents.
For instance, if $u =(0,1,1,0,1,0,1)$ and $v =(1,0,1,0,1,0,1)$ then$$ d_H(u,v) = |0-1|+ |1-0| + |1-1| + |0-0|+|1-1| + |0-0| + |1-1| = 3$$ because $u$ and $v$ have different bits at three positions.
The Hamming distance holds the properties of a metric (otherwise it would not be truly a distance):
- $d_H(x,y)\geq 0$ for any $x,y$ .
- $d_H(x,y)=0$ if and only if $x=y$ .
- $d_H(x,y) = d_H(y,x)$ for any $x,y$ .
- $d_H(x,y)\leq d_H(x,z) + d_H(z,y)$ for any $x,y,z$ .
If we realize that $d_H$ is counting something (positions where bits differ), then it's clear that $d_H$ can never be negative. Also, $d_H(x,x)= 0$ because a bit pattern has no different bits respect to itself, and if two bit patterns coincide on each position, they are indeed the same pattern, which proves the second property. The third condition also follows from the trivial fact that if $x$ differs at some position from $y$ , then $y$ differs at the sae position from $x$ .
We are left to prove the last condition (trangle inequality). If
then $d_H(x,y)$ counts at how many places does $x$ differ from $y$ . For instance, suppose that $x_3\neq y_3$ . This means that the third bits are different, which adds $1$ to the whole sum $d_H(x,y)$ .
Now, if $x_3\neq y_3$ it cannot happen that $x_3=z_3$ and $z_3=y_3$ at the same time, so we have that $x_3\neq z_3$ or $z_3\neq y_3$ . In either case, the sum $d_H(x,z) + d_H(z,y)$ also increases by one.
So, for each mismatch that increases $d_H(x,y)$ by one, $d_H(x,z)+ d_H(z,y)$ also increases by one. We conclude that$$ d_H(x,y)\leq d_H(x,z) + d_H(z,y).$$
|