Homework 6: Hash Tables & Stuff

Due: Thursday, December 6, 8:59:59pm



To allow us to automate part of the grading (what's the point of computers if they don't save us work, and do a better job to boot?), we are providing this assignment as a text file, which you must fill in and submit. You can use any text editor (vi, emacs, nano, etc.) to edit the file. Make sure you follow the directions exactly, fill in your answers where directed, and try to not modify any other part of the file. Otherwise, your homework might not be accurately graded.

How to submit: Here's the link for the file shown below: hw6.txt. Edit the file and copy into the hw6 submission directory on GL as usual. Name: Userid: CMSC 341 Fall 2018 Homework 6 ------------------------------------------------------------------- Question A (15 points) ------------------------------------------------------------------- [Adapted from problem R-9.8 in textbook] Hash the values 94, 11, 39, 20, 16, 5, 12, 44, 13, 88 and 23 into a hash table with 11 slots. Handle collisions by linear probing. Use the hash function: h(i) = (3 * i + 5) % 11 Type in each key on the same line as the index of the slot where it is eventually inserted. YOUR ANSWER TO QUESTION A: 0: 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: ------------------------------------------------------------------- Question B (20 points) ------------------------------------------------------------------- [Adapted from problem R-9.10 in textbook] Repeat Question A using double hashing instead of linear probing. Use the secondary hash function h'(k) = 7 - (k % 7). YOUR ANSWER TO QUESTION B: 0: 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: ------------------------------------------------------------------- Question C (35 points total) ------------------------------------------------------------------- We want to support the operations Insert(), Find() and Max() for a program that uses n Insert(), n Find() and 15 Max() operations. These operations can be performed in any order. The Max() operation simply reports the maximum valued stored in the data structure at the time of the call. 1. (5 points) Suppose that we use a red-black tree to support this program. What is the asymptotic worst case running time for n Insert(), n Find() and 15 Max() operations? (a) O(n) (b) O(n log n) (c) O(n^2) (d) O(n^2 log n) (e) O(n^3) Answer: 2. (5 points) BRIEFLY explain your choice above. 3. (5 points) Suppose that we use a binary max heap to support this program. What is the asymptotic worst case running time for n Insert(), n Find() and 15 Max() operations? (a) O(n) (b) O(n log n) (c) O(n^2) (d) O(n^2 log n) (e) O(n^3) Answer: 4. (5 points) BRIEFLY explain your choice above. 5. (5 points) Suppose that we use a hash table with a "good" hash function to support this program. What is the asymptotic "average" running time for n Insert(), n Find() and 15 Max() operations? (a) O(n) (b) O(n log n) (c) O(n^2) (d) O(n^2 log n) (e) O(n^3) Answer: 6. (5 points) BRIEFLY explain your choice above. 7. (5 points) Which of these three data structures would you pick to support n Insert(), n Find() and 15 Max() operations? Briefly justify your answer.