Hash Tables Flashcards
What is the makeEmpty() algorithm?
currentSize= 0;
For(0-Array.Length()) array[i] = null;
When do we check the load factor?
In the insert algorithm, after the insert is done.
What are the 10 functions that implement a Separate Chaining HashTable?
- Constructor()
- Constructor(size)
- Insert()
- Remove()
- Contains()
- MakeEmpty()
- Rehash()
- Hash()
- NextPrime()
- IsPrime()
What is the probability that an object will be inserted without a collision?
1-(the load factor)
What does HashTable(Size) do?
Sends size to nextPrime() and allocates an array of lists the size returned by nextPrime.
What is the remove algorithm?
- remove(object x)
- findPos(x);
- if(isActive(pos)) array.[pos].isActive = false;
What must be done after every insertion to a hashtable?
The size must be incremented.
What are the eleven methods of a quadratic probing table?
- makeEmpty()
- contains(object)
- insert(object)
- remove(object)
- hash()
- nextPrime(int)
- isPrime(int)
- rehash()
- findPos()
- isActive(int pos)
- allocateArray(int size)
For an ideal hash table, what is the mean number of probes needed to insert an object, or an unsuccessful search?
1⁄(1-∧)
What is hashing used for?
Hashing is used to perform insertions, deletions, and searches in constant average time.
In Java, if an Int is overflowed what happens?
The int becomes a negative value.
How does a hash Function work?
The hash function generally computes some hashcode from the objects key and then returns that hashCode mod tableSize
When do we check the load factor?
After every insertion.
What is the insert algorithm?
- insert(object x)
- int currentPos = findPos(x);
- if(isActive(pos)) return;
- Array[pos] = new HashEntry(x, true);
- if(++currentSize > array.length/2) rehash();
What is the contains algorithm?
- Contains(object x)
- int pos = findPos(x);
- return isActive(pos);
What are the average times for search and delete on a Hash Table that uses separate chaining?
1 + loadfactor/2
What is the load factor?
The load factor is the ratio of Nodes to tableSize.
Use horner’s rule on the following code:
for(int i = 0; i < key.length; i++)
hashcode + = key[i]*pow(26, i);
hashcode = 26*hashcode + key[i];
What is rehashing?
Building another table that is a prime more than twice as large as the last table size, then rehashing every element in the old table to a position in the new table.
What form of prime allows the entire table to be probed in a quadratic hash table?
A prime of form 4k + 3
what is generally the load factor for tables that do not use separate chaining?
it should be below .5
What is the probability of needing i probes to insert an object?
∧(i-1)(1 - ∧)
What collision resolution implementation gives the closest results to ideal run time?
Double Hashing
What is primary clustering?
Primary clustering is a behavior caused by linear probing that causes blocks of occupied cells to start forming due to linear collision resolution.