12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

356 Chap. 9 Searching9.5 Implement a database s<strong>to</strong>red on disk using bucket hashing. Define records <strong>to</strong>be 128 bytes long with a 4-byte key <strong>and</strong> 120 bytes of data. The remaining4 bytes are available for you <strong>to</strong> s<strong>to</strong>re necessary information <strong>to</strong> support thehash table. A bucket in the hash table will be 1024 bytes long, so each buckethas space for 8 records. The hash table should consist of 27 buckets (<strong>to</strong>talspace for 216 records with slots indexed by positions 0 <strong>to</strong> 215) followed bythe overflow bucket at record position 216 in the file. The hash function forkey value K should be K mod 213. (Note that this means the last threeslots in the table will not be home positions for any record.) The collisionresolution function should be linear probing with wrap-around within thebucket. For example, if a record is hashed <strong>to</strong> slot 5, the collision resolutionprocess will attempt <strong>to</strong> insert the record in<strong>to</strong> the table in the order 5, 6, 7, 0,1, 2, 3, <strong>and</strong> finally 4. If a bucket is full, the record should be placed in theoverflow section at the end of the file.Your hash table should implement the dictionary ADT of Section 4.4. Whenyou do your testing, assume that the system is meant <strong>to</strong> s<strong>to</strong>re about 100 or sorecords at a time.9.6 Implement the dictionary ADT of Section 4.4 by means of a hash table withlinear probing as the collision resolution policy. You might wish <strong>to</strong> beginwith the code of Figure 9.7. Using empirical simulation, determine the cos<strong>to</strong>f insert <strong>and</strong> delete as α grows (i.e., reconstruct the dashed lines of Figure9.8). Then, repeat the experiment using quadratic probing <strong>and</strong> pseudor<strong>and</strong>omprobing. What can you say about the relative performance of thesethree collision resolution policies?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!