So here is the actual question (this is for homework):
A hash table is a data structure that allows you to access and manipulate the date in constant time (O (1)). The hash table array must be initialized to zero during the creation of the hash table in order to identify empty cells. In most cases, the time penalty is huge, especially considering that most cameras will never be read. We ask you that you implement a hash table that bypasses this problem at the price of a heavier insert, but still in constant time. For this homework and to simplify your work, we assume that you cannot delete items in this hash table.
In the archive of this homework, you will find the hash table interface that you need to fill out. You can use the hashcode () function from java as a hash function. You will need to use the Vector data structure from Java to bypass initialization, and you must find how to do it yourself. You can only insert elements at the end of the vector so that the complexity is still O (1).
Here are some facts to consider:
In a hash table containing integers, the table contains numeric values ββ(but they do not make any sense).
On the stack, you cannot access elements above the highest element, but you know for sure that all values ββare valid. In addition, you know the index of the highest element.
Use these facts to get around the hash table initialization. To resolve conflicts, the table must use linear sensing.
Also, here is the interface I need to implement for this homework:
public interface NoInitHashTable<E> { public void insert(E e); public boolean contains(E e); public void rehash(); public int nextPrime(int n); public boolean isPrime(int n); }
I already implemented nextPrime and isPrime (I don't think they are different from a regular hash table). I need three others.
I thought about it a lot and discussed it with my teammate, but I really can't find anything. I only need to know the basic principle of its implementation, I can handle the encoding.
tl; dr I need to implement a hashtable array that works without initializing the array to zero at the beginning. Insertion should be performed at a constant time. I need to know only the basic principle of how to do this.
source share