Question: Implement a hash table. Call your class SimpleHashTable . You are to use a String array of 10 elements to store values. Keys will be

Implement a hash table. Call your classSimpleHashTable. You are to use a String array of 10 elements to store values. Keys will be integers. Implement the following methods:

  • public void put (int key, String value).. Adds value to array using key
  • public String get (int key). Gets value from array using key.
  • public string toString(). Prints a list of values stored in array with array index
  • public static int hash(int key, int size, int r). Hash using midsquare algorithm returns calculated array index

You are to use the midsquare hash algorithm, for size 10, r=2 (as discussed in class slides) to put and get keys.

Examples for midsquare with size = 10, r =2

276 -> 276 x 276 =76176

17 % 10 =7

hash(276, 10, 2) returns 7

42 -> 42 x 42 = 1764

76 % 10 = 6

hash(42, 10, 2) returns 6

This is a simple hashtable as you can assume that all keys will map to a unique index. See MIMIR for correct output.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Below is the implementation of the SimpleHashTable class with the required methods public class Simp... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!