home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / programm / 3391 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  1.9 KB

  1. Path: sparky!uunet!gatech!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
  2. From: dave@cs.arizona.edu (Dave Schaumann)
  3. Newsgroups: comp.programming
  4. Subject: Re: Locating duplicates
  5. Message-ID: <1993Jan2.041658.21596@organpipe.uug.arizona.edu>
  6. Date: 2 Jan 93 04:16:58 GMT
  7. References: <C07FJo.4vq@ux1.cso.uiuc.edu>
  8. Sender: news@organpipe.uug.arizona.edu
  9. Reply-To: dave@cs.arizona.edu (Dave Schaumann)
  10. Organization: University of Arizona
  11. Lines: 27
  12. In-Reply-To: ceblair@ux1.cso.uiuc.edu (Charles Blair)
  13.  
  14. In article <C07FJo.4vq@ux1.cso.uiuc.edu>, ceblair@ux1 (Charles Blair) writes:
  15. >   Given a large array of integers.  Is there a way to identify duplicates
  16. >which is substantially less work than sorting the array?
  17.  
  18. Hmm... imagine we have an array with just two elements that are equal.
  19. Now assume we have some duplicate finder which does not sort the array.
  20. Assuming that the values and positions of the data are not related in
  21. some way, it seems reasonable to assume that we can arrange the values
  22. so that that the algorithm must try every possible combination before
  23. it finds the duplicate pair.
  24.  
  25. Not an air-tight proof, but it seems reasonable to assert that no
  26. algorithm that asserts anything about the order of the values in
  27. the array can find a duplicate in less than O(n*(n-1)/2) time in the
  28. worst case, and clearly using an O(nlogn) sort and a linear scan
  29. is better than that.  To beat sort-and-scan, you would need some kind
  30. of linear-or-better ordering algorithm that would allow you to scan
  31. for duplicates with a linear-or-better scanning algorithm.
  32.  
  33. However, I think that generally you can do some things to speed up the
  34. average case of sort-and-scan.  For instance, you could modify a heap
  35. sort algorithm so that it stops as soon as it finds a duplicate.  Also,
  36. you could employ a hashing scheme based on the lowest bytes of the values,
  37. which would break up your data into 256 independant groups.
  38.  
  39. -- 
  40. Dave Schaumann            dave@cs.arizona.edu
  41.