Skip to main content

Section 11.6 HashMap Lab

Subsection 11.6.1 Counting word appearances using a Dictionary and a custom implementation

A Dictionary (sometimes called associative arrays) enable to store and retrieve (key, value) pairs. In this assignment, they will be useful to count how many times a particular word appears in Shakespeare’s work. The keys are going to be words. And the value associated with that key is going to be how many times that word appears. You will be building the hashmap yourself given the scaffolded code. The only file you will need to edit is the HashTabel.java file.

Subsection 11.6.2 Getting Started

  1. Get your IDE ready for a BRIDGES project and download the scaffold code: hashassignment.zip 1 
  2. Open up the HashTable.java file.
  3. Complete all the todo functions
  4. Plug in your credentials in PQBook.java.
  5. Run the program to see the visual of the hashtable

Subsection 11.6.3 Tasks to Complete

  1. Complete the get() function in HashTable.java | 10 pts
  2. Complete the set() function in HashTable.java | 10pts
  3. Complete the delete() function in HashTable.java | 10pts
  4. Complete the resize() function in HashTable.java | 10pts

Subsection 11.6.4 Functionality Information

The hashtable uses chaining for collisions so each index in the hashtable will hold a linked list of nodes. Each Node is an object that holds the key, value, and next position in the linked list.
The get() function is used to get a value from the hashtable using the key passed in as a parameter. You will get the index into the hashtable from the hash function and loop over the list at that index to get the object.
The set() function is used to set an object with the given key to a given value. If an object with the key is in the hashmap, you can set the object’s value. If not, add a new object with the key-value pair.
The delete() function removes an object from the hashtable given the key.
The resize() function resizes the hashtable once a loadFactor has been reached. This condition is calculated for you in the set() function. Once you set a new object in the hashtable, it checks if that loadFactor is reached. This relies on the count variable being accurate so update the count variable every time a new objects is added. If so, resize is called. In the resize function, you can interate over the hashtable by doing: for(Node node : this.table). This will get the first node at each index in the hashtable.
You have attempted of activities on this page.
uncc.instructure.com/courses/16965/files/21470970?wrap=1