죄송합니다. 이 페이지의 콘텐츠는 선택하신 언어로 제공되지 않습니다.

주요 내용으로 건너뛰기

Hamming distance

Hamming distance

(also hamming metric)

Hamming distance definition

Hamming distance, sometimes referred to as the hamming metric, is a method employed to determine the dissimilarity between two equal-length strings by tallying the number of positions where their respective symbols do not match. Within the realm of error detection and error correction codes, it calculates the bit flips needed to convert one binary code word into another.

Hamming distance examples

For example, the Hamming distance between the binary strings “10101010“ and “11001100“ is 4, as there are four positions where the bits differ.

Comparing the Hamming distance to other metrics

The Hamming distance is often compared to other string similarity metrics, such as the Levenshtein distance, which measures the minimum number of single-character edits (insertions, deletions, or substitutions) needed to change one string into another.

Pros and cons of the Hamming distance

Pros

  • Simple and easy to compute.
  • Useful for detecting single-bit errors in error-detecting codes.

Cons

  • Only applicable to strings of equal length.
  • Less flexible than other similarity metrics, such as the Levenshtein distance.

Tips for using the Hamming distance

When using the Hamming distance, ensure that the input strings are of equal length. If not, consider using an alternative similarity metric, such as the Levenshtein distance or the Jaccard similarity.