HammingDistance - Maple Help

Online Help

All Products    Maple    MapleSim


StringTools

  

HammingDistance

  

compute the Hamming distance between two strings

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

HammingDistance( s, t )

Parameters

s

-

Maple string

t

-

Maple string

Description

• 

The HammingDistance(s,t) command returns an integer measure of the distance between the two strings s and t.

• 

The Hamming distance between two strings s and t, of equal length, is the number of character positions where they differ. If strings s and t have respective lengths m and n where, without loss of generality, n<m, then the generalized Hamming distance between s and t is defined to be (m - n) + HammingDistance( s[ 1 .. n ], t ). The HammingDistance procedure computes this generalized metric.

• 

For a different notion of the distance between two strings, see StringTools[Levenshtein].

• 

All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

useStringToolsinHammingDistanceMathematics&comma;Mathematischeend use

4

(1)

withStringTools&colon;

HammingDistanceabc&comma;abd

1

(2)

HammingDistanceabc&comma;abcd

1

(3)

HammingDistanceElisabeth&comma;Elyse

6

(4)

HammingDistanceConnor&comma;Constance

6

(5)

Since it is a metric, the Hamming distance satisfies the triangle inequality.

sRandom1000&comma;lower&colon;

tRandom1000&comma;lower&colon;

uRandom1000&comma;lower&colon;

HammingDistances&comma;t

955

(6)

HammingDistances&comma;u+HammingDistanceu&comma;t

1926

(7)

See Also

string

StringTools

StringTools[Levenshtein]