home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / programm / 2566 < prev    next >
Encoding:
Text File  |  1992-09-03  |  2.9 KB  |  70 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!ulowell!news.bbn.com!usc!sdd.hp.com!news.cs.indiana.edu!umn.edu!thompson
  3. From: thompson@atlas.socsci.umn.edu (T. Scott Thompson)
  4. Subject: Re: How to find vectors with minimum Hamming-distance?
  5. Message-ID: <thompson.715537752@hermes.socsci.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: hermes.socsci.umn.edu
  8. Reply-To: thompson@atlas.socsci.umn.edu
  9. Organization: Economics Department, University of Minnesota
  10. References: <1992Sep3.132931.2083@email.tuwien.ac.at>
  11. Date: Thu, 3 Sep 1992 16:29:12 GMT
  12. Lines: 56
  13.  
  14. rainer@ruble.fml.tuwien.ac.at (Rainer Staringer) writes:
  15.  
  16. >I stumbled over the following problem recently, and I wonder if there
  17. >is a clever algorithm for it: I have a set of n m-dimensional vectors
  18. >(vector elements are from a finite set, but not necessarily binary),
  19. >and I want to find the 2 vectors with the minimum Hamming-distance
  20. >(i.e. those which have the most elements in common). Is there any
  21. >way you can find them using less than O(n^2) vector comparisons?
  22. >I know there is a clever algorithm for the equivalent problem with
  23. >Euclidean metric, but I could not find any for the Hamming-metric
  24. >variant.
  25.  
  26. How about this (off the top of my head): If the vectors are drawn from
  27. a finite set then the problem can be transformed into a finite
  28. collection of sorting problems, each of which can be solved faster
  29. than O(n^2).  Here is what I have in mind.
  30.  
  31. min-dist := m+1;
  32. <initialize vector-array>;
  33. for <every permutation of the coordinate system> do
  34.    begin
  35.    <sort vector-array according to the lexicographic ordering induced by the
  36.     current labelling of the coordinates>
  37.    min-this-time := m+1
  38.    for i := 1 to n-1 do
  39.       begin
  40.       current-dist := m - #zeros( vector-array(i) - vector-array(i+1) );
  41.       if current-dist < min-this-time then
  42.          begin
  43.          v1 := vector-list(i);
  44.          v2 := vector-list(i+1);
  45.          min-this-time := current-dist;
  46.          end;
  47.       end;
  48.    if min-this-time < min-dist then
  49.       begin
  50.       p1 := <inverse-of-current-permutation>(v1);
  51.       p2 := <inverse-of-current-permutation>(v2);
  52.       min-dist := min-this-time;
  53.       end;
  54.    end;
  55.  
  56. At the end the vectors p1 and p2 will hold two points achieving the
  57. minimum distance.  The distance itself is in min-dist.
  58.  
  59. The time, considered as a function of n, will be dominated by the
  60. "sort" statment, which can be done faster than O(n^2) if you do it
  61. right.  The main drawback is that the outer loop must be executed
  62. O(m!) times.  Some improvement on this is clearly possible (e.g. never
  63. check both a given permutation and its reverse-ordering), but I
  64. wouldn't use this for m! big relative to n.  How big is m in your
  65. application?
  66. --
  67. T. Scott Thompson              email:  thompson@atlas.socsci.umn.edu
  68. Department of Economics        phone:  (612) 625-0119
  69. University of Minnesota        fax:    (612) 624-0209
  70.