Lab 10: Hash Tables
CS 241: Data Structures,
Fall 2007
Due Date: class on Wednesday Nov 28
Goals for this assignment are to:
- Understand Hash Table Collision Detection Algorithms
- Demonstrate how Hash Tables are used.
Reading
Review Chapter 11.4
Part 1: A Simple Hash Table with Collision Detection
- In this part of the lab, you are to write, from scratch, a very simple hash table program. Your program should be much simpler than the one given in the text.
Your Hash Table class
will store only non-negative integers in a simple integer array (the user should be able to set the size).
Initialize the elements of the hash table array to -1 to indicate an "empty" slot.
If you want, you may start with the skeleton program.
In the HashTable class you need to implement the methods:
- public int insert(int n) - inserts an item using linear probing. Returns the
number of collisions encountered while trying to insert the item. Returns -1 if table is full.
You will need to think about how to count collisions.
- public int contains(int n) - checks to see if an item is in the table, assuming that
the item was entered using linear probing. Returns -1 if item is not in the table otherwise return
the number of collisions.
- public int remove(int n) - checks to see if an item is in the table, assuming that
the item was entered using linear probing. If yes, remove the item. Returns -1 if item is not in the table otherwise return
the number of collisions.
- public String toString() - return a string representation of the hash table indicating
what items are in which slots and which slots are empty. Differentiate between slots that are
empty because they never contained an item and those that are empty because an item was
removed.
-
Think about how the above methods would change if you instead used quadratic probing.
Part 2: A SpellChecker Program
Contractions won't be parsed correctly (e.g. didn't, can't, etc). This could be fixed
by using regular expressions, however, this is a bit beyond the scope of this lab.
Evaluation
By no later than class on Wednesday November 28, you should zip together both projects, including a jar files, and email the code as an attachment to gorr@willamette.edu. Place
CS241 Lab 10 in the subject line.
Demonstrate your the hash table program (part 1) and and the spell check program (part 2).
[top] [Schedule]
[Home]