The data structure & algorithm class that I'm taking now is a lot of pen and paper understanding of how algorithms work, but very little actual coding. I'm kind of a programming noob, so this may be a stupid question to some of you.
Conceptually, I understand hashing, and the reasons for the different methods, but am lost on how to code this assignment.
Basically we can use any source code that we want. The codes from the book are http://users.cis.fiu.edu/~weiss/dsaajava3/code/SeparateChainingHashTable.java and http://users.cis.fiu.edu/~weiss/dsaajava3/code/QuadraticProbingHashTable.java
When using either of these codes, I seem to have trouble inserting the keys into the table. I'm using this block to insert:
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(99999);
for (int i = 0; i < 100; i++) {
H.insert(""+randomInt);
}
This doesn't seem to actually insert anything into the table, however, the size remains constant despite the amount of insertions. Also, I have no idea how to determine how many probes were needed.
Try this, you have one line in bad place.
I case of probing:
If I correctly understand: This method is performing probing, yes? So You have to count how many times this method is called in two options: duplicate, and not duplicate. Use some flag if current element added is duplicated and two integers. In this method add
if
for checking flag and increase one of counters. You will have number of probes.Edit:
You have to use HashTable which use probing and test the amount of probing(average). You have quadric probing algorithm in
public class QuadraticProbingHashTable<AnyType>
. And you have to set hash table length to 1019. In first exercise you have to use linear probing. So Basically you have to use HashTables with specified preconditions when you start adding elements.This is linear probing algorithm
This is double hash alhorithm
You have to implement this in your hash table and check how many times it will be used. I think that it will somehow show how many collisions it generates. Happy coding. Quadric algorithm is done, only you have to set preconditions)(hardcode starting value to 1019).