Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the Java source files HashEntry.java and HashMap.java provided 1. Create a hash table that is made of elements HashElement(int Key, String Value).The size of

Use the Java source files HashEntry.java and HashMap.java provided

1. Create a hash table that is made of elements HashElement(int Key, String Value).The size of hash table will be 137.

2. Implement the following methods for the hash table:

a. put(int Key, String Value):

1 Puts the key value pair in the hash table at a certain index.

2You need to implement a simple hash function H(key) = key mod mapsize to find the index where you will put the pair.

3 If collision occurs, i.e., a pair already exists in that index and the key is not the same as the current key, then you will use this function to resolve the collision, H(key)=(7*H(key)+1) mod mapsize, until you get an empty slot.

4 If the index is already full and the keys are the same, just replace the old value with the new one.

b. get(int Key):

1) Gets the value associated with the Key.

2) You should not do linear search throughout the hash table for the key, rather you will calculate the index using the hash function stated above, go directly to that index and retrieve the value

3. (1) Implement linear probing to put a new value in your hash table. The sequence of probes are H(key) = (H(key) + i) mod mapsize for i = 0, 1, 2, 3, ... and so on.

(2) Implement quadratic probing to put a new value in your hash table. The sequence of probes are H(key) = (H(key) + i2) mod mapsize for i = 0, 1, 2, 3, ... and so on.

4. Write a driver program to test your implementation of hash table. Allow the user to put or get data.

HashEntry.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

public class HashEntry {

private int key;

private String value;

HashEntry(int key, String value) {

this.key = key;

this.value = value;

}

public int getKey() {

return key;

}

public String getValue() {

return value;

}

public void setValue(String val) {

this.value = val;

}

}

HashMap.java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

public class HashMap {

private final static int TABLE_SIZE = 137;

HashEntry[] table;

HashMap() {

//Implement

}

public String get(int key) {

// Implement

}

public void put(int key, String value) {

// Implement

}

public void linearProbe(int key, String value){

// Implement

}

public void quadraticProbe(int key, String value){

// Implement

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions