hw06solutions - CSE 331 Spring 2008, Section 1 Homework 6...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 331 Spring 2008, Section 1 Homework 6 Solutions 1. (a) Assuming that we append new items to the tail of each chain, the resulting hash table will look like this. For a hash table that appended new items to the head of the chain, the chains in cells 3 and 9 would be reversed. Table index Value(s) 0 1 4371 2 3 1323 → 6173 4 4344 5 6 7 8 9 4199 → 9679 → 1989 (b) Values that collided upon insertion are marked with asterisks. The number of asterisks indicates the number of subsequent probe attempts required to place that value. Table index Value 0 9679* 1 4371 2 1989*** 3 1323 4 6173* 5 4344* 6 7 8 9 4199
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(c) Table index Value 0 9679* 1 4371 2 3 1323 4 6173* 5 4344* 6 7 8 1989*** 9 4199 (d) Entering the input sequence into h 2 ( x ) gives the following values: {4, 7, 1, 1, 3, 2, 6}. These will be used as probe distances in the event of a collision. Table index Value 0 1 4371 2 3 1323 4 6173* 5 9679*** 6 7 4344* 8 9 4199 The value 1989 initially hashes to table index 9. Inserting here collides with 4199, so double hashing is applied to probe for a new location. This leads us to try indices 5, 1, 7, 3, and then 9 again. Any further probing would just try the same indices over and over again. Thus, the insertion of 1989 fails. 2. (a-c) See hw06main.cpp, hw06table.cpp, and hw06table.h for a reference implementation.
Background image of page 2
(d) The following times were recorded on arctic, using the hash function given in Figure 5.4 of the text and in the lecture slides. All times are in seconds. Load factor 0.2 0.4 0.6 0.8 0.9 Hash table insert .029227 .061437 .108697 .205247 .435195 Hash table successful search .029300 .065810 .118835 .257224 .604485 Hash table failed search .026314 .074193 .200975 1.08125 6.59863 Set insert .144479 .305189 .471497 .643131 0.731994 Set successful search .068244 .147732 .227742 .311891 0.359462 Set failed search .096601 .199052 .288739 .386365 0.433462 For adriatic, the following times were obtained. Load factor 0.2 0.4 0.6 0.8 0.9 Hash table insert .001695 .003406 .006123 .011165 .023375 Hash table successful search .001535 .003383 .006259 .014300 .031313 Hash table failed search .001369 .003778 .010265 .055998 .368926 Set insert .007082 .015494 .023591 .032866 .039617 Set successful search .003755
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

Page1 / 6

hw06solutions - CSE 331 Spring 2008, Section 1 Homework 6...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online