Assignment 6 -- due Thursday, October 17 at the beginning of lab
CS 5521 Fall Semester, 2013
35 Points
(version 0.92)

Topics: Hash Tables - Theory and Practice

The assignment has three parts. In Parts 1 and 2, you code and test hash tables based on chaining and open addressing, respectively. Part 3 consists of exercises on hash tables.

Part 1: Coding Hash Tables Using Chaining (10 points)

For both Parts 1 and 2, implement the "dictionary" operations: insert, delete, and search. An operation ShowTable is provided (not in the text) that displays the hash table structure graphically.

In Part 1, implement a ChainHash class that handles collision resolution via chaining. Implement the insert, delete, and search operations, as well as a ShowTable method (see below).

How to Test. You will test your hash table operations on files I provide, containing commands to invoke the various dictionary operations. These operations are:

c construct an empty table (done in the command interpreter)
i key insert node with key key into the table
d key delete node with key key from the table
s key search for node with key key in the table
S Show (display) the table structure
# echo the comment line

Initially in the command interpreter constructs an empty hash table on which all subsequent operations will be performed. The 'i', 'd', and 's' commands work just as described in Chapter 11. The 'S' command Shows the hash table structure: for each slot, print the linked list using the Show() method in the linked list class, LList. Finally, a line beginning with a '#' the line is interpreted as a comment and simply echoed to standard output. Lines beginning with any other character are ignored.

For Part 1, use m = 9, and hash function h(k) = k mod 9.

You can use a modified command interpreter from previous labs. For the tests that you hand in, commands will be processed in batch mode (i.e., read from files). However, you may want to modify the command interpreter so that it can read commands from standard input as well so that you can more conveniently test simple operations in the early stages.

Helpful code: Here is a .h file for the LList class llist.h, and code for the linked list class implementation llist.cpp. Here is a .h file for the ChainHash class chainhash.h, and skeleton code for the chained hash class implementation chainhash.cpp. Here is a command interpreter: cmdint.cpp. Here is a "Makefile" that puts it all together: Makefile. When you download these files, be sure to remove the ".txt" suffixes (by moving them to the same file name without the ".txt").

Part 2: Coding Hash Tables Using Open Addressing (10 points)

For this part, implement an OpenHash class with the three dictionary functions insert, delete, and search. In this class, the ShowTable() method will just show the table, T, which is just an array (of integers). For this part, since 0 is a valid array index, it is probably safest to encode NIL as -1, and therefore DELETE as -2. Since the arguments of the insert and delete operations are different in Parts 1 and 2, it is probably best to modify the command interpreter (see below).

For Part 2, use m = 11, and linear probing with hash function h(k,i) = (h'(k) + i) mod 11, where the auxiliary hash function h'(k) = k mod 11.

Helpful code: Here is a .h file for the OpenHash class openhash.h, and skeleton code for the chained hash class implementation openhash.cpp. Here is a command interpreter for Part 2: cmdint2.cpp. Here is a "Makefile" that puts it all together: Makefile2. When you download these files, be sure to remove the ".txt" suffixes (by moving them to the same file name without the ".txt"). Also you probably want to put the files in a different directory than those of Part 1. Finally, if you use the makefile, be sure to save it as "Makefile" (i.e. without the suffix "2.txt").

What To Hand In for both Parts 1 and 2.

Hand in typescripts for the test files: Identify each script clearly. Also, hand in well-documented code for your hash table operations, in separate modules.

Part 3: Hash Table Exercises (15 points)

  1. (3 points) Do exercise 11.2-2, p. 261.
  2. (8 points) Do exercise 11.4-1, p. 277.
  3. (4 points) Do exercise 11.4-2, p. 277.

Page URL: http://www.d.umn.edu /~ddunham/cs5521f13/assignments/a6/assignment.html
Page Author: Doug Dunham
Last Modified: Thursday, 10-Oct-2013 16:16:23 CDT
Comments to: ddunham@d.umn.edu