Talk:Hamming distance

From Wikipedia, the free encyclopedia

[edit] Distance vs. difference

Why the difference between the bits called as "Hamming distance" and not "Hamming difference" —Preceding unsigned comment added by 163.152.45.51 (talk • contribs)

I don't know the historical reasons, but I can think of a couple of plausible explanations. First, Hamming distance forms a metric and functions with that property are often called distances. Second, the difference of A and B is a quantity that, when added back to B, gives A again; that is, it is inverse to addition. Hamming distance doesn't have that property, so it doesn't make sense to call it a difference. One function that is called a difference and is closely related to Hamming distance is the symmetric difference. —David Eppstein 04:53, 5 January 2007 (UTC)

[edit] 2-D graph

What about the hamming distance between two points in a 2-D graph for example? —The preceding unsigned comment was added by 128.200.69.104 (talk • contribs).

[edit] Source code

Per Wikipedia:WikiProject Computer science/Manual of style (computer science) (a draft in progress, but I think very relevant), "Multiple source code implementations are not appropriate unless they contrast specific aspects of the code and that contrast is important to the encyclopedic content of the article. If possible, accentuate differences by providing the alternate implementation in the same language as the original." The article had three implementations, not very different; I kept the most compact of them (the Python), modified the most different of them to be even more different (the C++, which uses numeric arguments rather than strings, and which I modified to take time proportional to the number of differing bits rather than the total bitlength of the arguments to further differentiate it from the Python), and removed the third example (Javascript) which I think does not add anything vis-a-vis the other two: it is not significantly different algorithmically from the Python, and its added length relative to the Python has more to do with Javascript programming than anything relevant to Hamming distance. For reference, here is the removed code:

function hamdist(s1, s2)
{ 
   // We alert user if the two strings differ in length.
   if (s1.length != s2.length) {
      alert("Both sequence must be of the same length!");
      return -1;
   }
   
   var distance = 0;      // zero = no difference between two strings.
   
   // Match the two strings, character by character.  If they are NOT
   // identical, increment distance by 1.
   for(var i = 0; i < s1.length; i++)
      if (s1.charAt(i) != s2.charAt(i))
         distance++;
   return distance;
}

David Eppstein 06:46, 8 June 2007 (UTC)