CS367 Homework 8
Lecture 3, Fall 2015
Due by 11:59 pm on Friday, December 4 (not accepted late)

Announcements

Check here periodically.

11/23/2015  Homework assigned. To ask questions about the homework and see questions posed by other students and their answers, go to: https://piazza.com/wisc/fall2015/cs3673 and sign-in using your wisc.edu account.

Questions

Homework assignments must be done individually. Collaboration on homework assignments is not allowed.

Question 1:

The ten most common words in English, along with their hash codes according to Java's String.hashCode method, are:

OrderWordHash Code
1the114801
2of3543
3to3707
4and96727
5a97
6in3365
7is3370
8it3371
9you119839
10that3558823

Suppose these strings are inserted into a 14-bucket hash table in the order shown above. Each string's bucket is its hash code modulo 14. If collisions occur, each bucket is implemented as a singly-linked list, with new items added to the head of the list. Show the contents of all buckets after these strings are inserted. Give each bucket as a bucket number followed by a list of strings, with the head of the list at the left.

Question 2:

A bank with many branches in multiple districts needs to be able to access accounts in order to record transactions (such as deposit or withdraw). It has been decided that hashtables will be used to store account information. Each individual branch will have its own hashtable and store only the accounts for its customers. Each account contains the following information:

  • name of account holder (up to 20 characters)
  • 10-digit account number
  • current balance

The account numbers have the following properties:

  • the first 2 digits are the district number,
  • the next 2 digits are the branch number,
  • the next 5 digits are assigned sequentially to accounts starting with 10000, and
  • the last digit is 1, 2, or 3 depending on whether the account is a checking, savings, or CD account.

The programmer implementing the hashtable for the bank is considering 4 different hash functions:

hash1: hash on the name
hash2: hash on the first 5 digits of the account number
hash3: hash on the last 5 digits of the account number
hash4: hash on the balance

Part A: Which of the hash functions above is the best for this situation? Briefly explain why.

Part B: For each of the 3 remaining hash functions, briefly explain the problems/disadvantages with the hash function that make less suitable for this situation.

Handing in

Please include your name at the top your file.

Put your answers to the questions into one file named Homework8 with the appropriate file extension, e.g., Homework8.pdf (see File Format for acceptable file formats).

Electronically submit your work to the Homework 8 Dropbox on Learn@UW.

Last Updated: 10/23/2015     © 2015 Beck Hasti & Charles Fischer