home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!caen!batcomputer!cornell!karr
- From: karr@cs.cornell.edu (David Karr)
- Subject: Re: Locating duplicates
- Message-ID: <1993Jan7.173822.12773@cs.cornell.edu>
- Organization: Cornell Univ. CS Dept, Ithaca NY 14853
- References: <1993Jan5.043456.29130@micor.ocunix.on.ca> <1993Jan5.224141.21639@organpipe.uug.arizona.edu> <1993Jan7.021146.2290@cs.cornell.edu>
- Date: Thu, 7 Jan 1993 17:38:22 GMT
- Lines: 37
-
- In article <1993Jan7.021146.2290@cs.cornell.edu> karr@cs.cornell.edu (David Karr) writes:
- >A shortcoming of course is that the running-time analysis is valid
- >only if you can repeatedly allocate large amounts of zeroed-out memory
- >in a small (essentially constant) time. But pessimistic assumptions
- >about memory initialization are bad for other index-array algorithms
- >as well.
-
- Mark Tillotson objected that my assumption about O(1) memory
- allocation was a bad one. In fact I ran some benchmarks on a Sun 4
- and found that the running time of calloc() was proportional to k
- where K is the number of bytes allocated and initialized to 0. (I
- also noticed that allocating new space took 4 times as long as
- reallocating freed space, perhaps virtual memory management is even
- more expensive than traversing the physical memory?)
-
- In fact the time required for all the allocations in my algorithm was
- about 40 seconds on the Sun 4. What a shame! It seems that support
- for large blocks of data initialized to a constant byte value would be
- quite practical in hardware and a useful feature to support.
-
- Mark Tillotson also suggests a second pass over each sublist of the
- input in order to clear all the bit flags that were set for that list.
- This makes the algorithm once again proportional to N (though with
- almost twice the constant factor) with a much smaller constant term,
- i.e. whatever it takes to allocate one copy of the flag array. In
- that case I believe it makes sense to use a much smaller flag array,
- say 2^16, with a correspondingly larger array for head-of list, in
- this case 2^13 entries. Then the constant term will be something on
- the order of 2^16 instructions (note you should be able to zero out
- the bit vector four bytes at a time). Still I suspect for fairly
- small problem sizes a fast O(n log n) sort will still win, and it's
- quite possible that Mark Tillotson's hashing scheme has better
- average-case performance on any problem size.
-
- -- David Karr (karr@cs.cornell.edu)
-
-
-