Implement an eager delete() method for linear probing hash
table. The eager delete will delete the pair from the hash table,
not just set the value to null.
*Algorithhms*
In Java Language Please
I want to add the delete method to this hash table
code.
![public class Linear ProbingHashST<Key, Value> private int M = 30001; private Value [] vals = (Value[]) new Object[M]: private](http://img.homeworklib.com/questions/ff0f7f70-8429-11eb-a6c1-b7f73bdfbc0a.png?x-oss-process=image/resize,w_560)
![private Value get(key key) {/ previous slide */ } public void put(key key, Value val) int i; for (i = hash (key); keys[i] !=](http://img.homeworklib.com/questions/ffba2980-8429-11eb-9654-bdd54cf5b5b1.png?x-oss-process=image/resize,w_560)
Here is the Solution :
I have added boolean remove(final long key) to delete the item & Created One Test class UsageHash to test the functionality. I have explained all important lines by using Java comments.
class HashTableEx {
final int SIZE = 300001; // size of the table
long[] a = new long[SIZE]; int[] ex = new int[SIZE];
// adds new key
boolean add(final long key) {
int i = h(key), j = 1;
for (; ex[i] != 0; i = (i + 1) % SIZE, j++)
if (a[i] == key)
return false;
ex[i] = j;
a[i] = key;
return true;
}
// returns true, if key is
contained in the table
boolean contains(final long key) {
for (int i = h(key); ex[i] != 0; i = (i + 1) % SIZE)
if (a[i] == key)
return true;
return false;
}
// removes key from the table
boolean remove(final long key) {
for (int i = h(key); ex[i] != 0; i = (i + 1) % SIZE)
if (a[i] == key) {
ex[i] = 0;
compress(i);
return true;
}
return false;
}
// compresses lists
void compress(int free) {
int i = (free + 1) % SIZE, off = 1;
for (; ex[i] != 0; i = (i + 1) % SIZE, off++)
if (ex[i] > off) {
// move current element
a[free] = a[i];
ex[free] = ex[i] - off;
// mark current slot as free
ex[i] = 0;
off = 0;
free = i;
}
}
int h(final long key) {
return (int) Math.abs(key % SIZE);
}
}
public class UsageHash
{
public static void main(String[] args)
{
//Creating instance of HashTableEX
HashTableEx objh=new HashTableEx();
objh.add(12);
objh.add(13);
//Checking if 12 Exist !!! before Removing
System.out.println("Output Before Deletion :"
+objh.contains(12));
//Removing 12 From HashTableEx
objh.remove(12);
//Checking Hash Table after Removing 12
System.out.println("Output After Deletion :"
+objh.contains(12));
}
}
Implement an eager delete() method for linear probing hash table. The eager delete will delete the...
The task of this project is to implement in Java Hash Table structure using Linear Probing Collision Strategy. You can assume that no duplicates or allowed and perform lazy deletion (similar to BST). Specification Create a generic class called HashTableLinearProbe <K,V>, where K is the key and V is the value. It should contain a private static class, HashEntry<K,V>. Use this class to create array to represent Hashtable: HashEntry<K,V> hashtable[]; Implement all methods listed below and test each method...
Java you are required to add a public Object get( Object key) method into the Hashtable class. As defined in the Java documentation, the get() method returns the value with which the specified key is associated, or null if this hash table contains no record for the key. More formally, if this hash table contains a mapping from a key k to a value v such that (key.equals(k)), then this method returns v; otherwise it returns null. (There can be...
In C++ I am trying to implement a log base 2 hash table utilizing the shift function. So, the code determines the position of where the value will be stored using log2. But am having issues using the shift part as everything just wants to pile on to zero. //ChainingHash - log2 #include<iostream> #include<vector> #include<iterator> #include<string> #include<cmath> using namespace std; #define BUCKET 10 //no. of buckets class Hash { vector<int>*table; //ptr containing buckets public: Hash();...
Identify the letters and anything associated with it. It is a hash map so please feel free to point out the other important parts beside the arrows. I apologize for the order of the pictures class HashMap private: HashEntry table ; public: HashMap() table-new HashEntry * [TABLE_SIZE]; for (int 1-0; 1< TABLE SIZE: i++) table [i] = NULL; Hash Function int HashFunc(int key) return key % TABLE-SIZE; Insert Element at a key void Insert(int key, int value) int hashHashFunc(key); while...
Implement the remove() and the rehash() methods for the following externally chained hash table. Note you should rehash when "size > arraySize" at the start of the put() method. The new size of the arraySize should be "(2 * old array size) + 1" import java.util.ArrayList; import java.util.Hashtable; import java.util.LinkedList; import java.util.Map; public class ExternalChainingHashTable<K,V> { private class Mapping { private Mapping next; private K key; private V value; private Mapping(K key, V value) { this.key = key; this.value =...
Java Quadratic Probing Hash table HELP! Complete the Map and Entry class provided in Map.java. Create a tester/driver class to show the Map class is working as intended. Methods/Constructor correctly completed (2pt) This is the Map class methods Map(), put(key, value), get(key), isEmpty(), makeEmpty() Private class correctly completed (2pt) This is the Entry class methods Add the methods that are required for this to work correctly when stored in the QuadraticProbingHashTable Tester class (1pt) Show the methods of the Map...
PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...
C++ assignment - Hash table with linear probing --- implement in single file - main.cpp You are asked to implement a very specific hash table. The keys are lower-case English words (e.g., apple, pear). The length of a key is at most 10. The hash function is “simply using the last character”. That is, the hash value of apple should be e, and the hash value of pear should be r. Your hash table contains exactly 26 slots (hash value...
Hash Tables. (Hint: Diagrams might be helpful for parts a) and b). ) When inserting into hash table we insert at an index calculated by the key modulo the array size, what would happen if we instead did key mod (array_size*2), or key mod (array_size/2)? (Describe both cases). Theory answer Here Change your hashtable from the labs/assignments to be an array of linkedlists – so now insertion is done into a linkedlist at that index. Implement insertion and search. This...
I need help fixing my java code for some reason it will not let me run it can someone pls help me fix it. class LinearProbingHashTable1 { private int keyname; private int valuename; LinearProbingHashTable1(int keyname, int valuename) { this.keyname = keyname; this.valuename = valuename; } public int getKey() { return keyname; } public int getValue() { return valuename; } } class LinearProbingHashTable2 { private final static int SIZE = 128; LinearProbingHashTable2[] table; LinearProbingHashTable2() { table = new LinearProbingHashTable2[SIZE]; for (int...