Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Scenario Develop an algorithm to search and remove data from a hash table using the open addressing technique. Aim Implement a hash table using open
Scenario
Develop an algorithm to search and remove data from a hash table using the open addressing technique.
Aim
Implement a hash table using open addressing with linear probing.
Prerequisites
To solve this activity, you have to implement the following methods in the OpenAddrHashTable.java file:
public void putK key, V value
private int searchPositionK key
public void removeK key
public Optional getK key
Steps for Completion
Study the pseudocode shown in Snippet and Snippet shown below and implement them in Java.
The container class OpenAddrPair will hold your key and value in the hash table.
Have a flag on this container to indicate when an item is deleted.
Use this flag in the put operation to overwrite it if it is deleted. You can use this flag to optimize your get method using the filter method.
insertkey value, array
s lengtharray
hashValue hashkey s
i
while i s and arrayhashValue i mod s null
i i l
if i s arrayhashValue i mod skey value
Snippet : Psuedocode for inserting using linear probing
searchkey array
s lengtharray
hashValue hashkey s
i
while i s and arrayhashValue i mod s null and arrayhashValue i mod skey key
i i
keyValue arrayhashValue i mod s
if keyValue null && keyValue.key key return keyValue.value
else return null
Snippet : Solution pseudocode for searching using linear probing
Grading
Complete each task listed below. Each task contains automated checks which are used to calculate your grade. When you have completed each task by clicking the checkbox, open the task list panel on the left navigation bar and click the "Submit" button.
codes provided:
HashProvider.java
public interface HashProvider
int hashKeyK key, int tableSize;
HashTable.java
import java.util.Optional;
public interface HashTable
void putK key,V value;
Optional getK key;
void removeK key;
OpenAddrHashTable.java
import java.util.Optional;
public class OpenAddrHashTable implements HashTable
private final HashProvider hashProvider;
private Pair array;
public OpenAddrHashTableint capacity, HashProvider hashProvider
array new Paircapacity;
this.hashProvider hashProvider;
public void putK key, V value
write your code here
private int searchPositionK key
write your code here
public void removeK key
write your code here
public Optional getK key
write your code here
return Optional.empty;
OpenAddrPair.java
public class OpenAddrPair
private final K key;
private final V value;
private boolean deleted;
public OpenAddrPairK key, V value
this.key key;
this.value value;
this.deleted false;
public K getKey
return key;
public V getValue
return value;
public boolean isDeleted
return deleted;
public void setDeletedboolean deleted
this.deleted deleted;
Pair.java
public class Pair
private final K key;
private final V value;
public PairK key, V value
this.key key;
this.value value;
public K getKey
return key;
public V getValue
return value;
RemainderHashing.java
public class RemainderHashing implements HashProvider
public int hashKeyInteger key, int tableSize
return key tableSize;
public static void mainString args
RemainderHashing remainderHashing new RemainderHashing;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
System.out.printlnremainderHashinghashKey;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started