11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

338 Chap. 9 Searching9.16 Assume th<strong>at</strong> you have a ten-slot closed hash table (the slots are numbered0 through 9). Show the final hash table th<strong>at</strong> would result if you used thehash function h(k) = k mod 10 <strong>and</strong> pseudo-r<strong>and</strong>om probing on this list ofnumbers: 3, 12, 9, 2, 79, 44. The permut<strong>at</strong>ion of offsets to be used by thepseudo-r<strong>and</strong>om probing will be: 5, 9, 2, 1, 4, 8, 6, 3, 7. After inserting therecord with key value 44, list for each empty slot the probability th<strong>at</strong> it willbe the next one filled.9.17 Wh<strong>at</strong> is the result of running sfold from Section 9.4.1 on the followingstrings? Assume a hash table size of 101 slots.(a) HELLO WORLD(b) NOW HEAR THIS(c) HEAR THIS NOW9.18 Using closed hashing, with double hashing to resolve collisions, insert thefollowing keys into a hash table of thirteen slots (the slots are numbered0 through 12). The hash functions to be used are H1 <strong>and</strong> H2, defined below.You should show the hash table after all eight keys have been inserted.Be sure to indic<strong>at</strong>e how you are using H1 <strong>and</strong> H2 to do the hashing. FunctionRev(k) reverses the decimal digits of k, for example, Rev(37) = 73;Rev(7) = 7.H1(k) = k mod 13.H2(k) = (Rev(k + 1) mod 11).Keys: 2, 8, 31, 20, 19, 18, 53, 27.9.19 Write an algorithm for a deletion function for hash tables th<strong>at</strong> replaces therecord with a special value indic<strong>at</strong>ing a tombstone. Modify the functionshashInsert <strong>and</strong> hashSearch to work correctly with tombstones.9.20 Consider the following permut<strong>at</strong>ion for the numbers 1 to 6:2, 4, 6, 1, 3, 5.Analyze wh<strong>at</strong> will happen if this permut<strong>at</strong>ion is used by an implement<strong>at</strong>ion ofpseudo-r<strong>and</strong>om probing on a hash table of size seven. Will this permut<strong>at</strong>ionsolve the problem of primary clustering? Wh<strong>at</strong> does this say about selectinga permut<strong>at</strong>ion for use when implementing pseudo-r<strong>and</strong>om probing?9.7 Projects9.1 Implement a binary search <strong>and</strong> the quadr<strong>at</strong>ic binary search of Section 9.1.Run your implement<strong>at</strong>ions over a large range of problem sizes, timing theresults for each algorithm. Graph <strong>and</strong> compare these timing results.

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

Saved successfully!

Ooh no, something went wrong!