Hashing and Hash Tables Flashcards
What is a hash table?
A collection of items which are stored in such a way as to make it easy to find them later.
What is the correct name for each position within a hash table?
A slot.
What is a hash function?
The mapping between an item and the slot where that item belongs in the hash table.
What does the load factor refer to?
The number of slots within a hash table that are occupied.
What is the calculation for the load factor?
Number of items divided by the hash table size.
What does a collision or a clash refer to?
When two items need to be in the same slot within a hash table.
What is a perfect hash function?
A hash function which maps each item into a unique slot.
What is the complexity of search of a hash table?
O(1).
What is the folding method for constructing a hash function?
It divides the item into equal-size pieces, which are then added together to give the resulting hash value, which is remainder divided by the size of the hash table.
What is the mid-square method for constructing a hash function?
It squares the item, then extracts a portion of the resulting digits, which are then divided by the number of slots within the hash table.
Why does the hash function have to be efficient?
So that it does not become the dominant part of the storage and search process.
What does collision resolution refer to?
A systematic method for placing the second item of two items which have collided.
How does open addressing work?
Moving through the hash table sequentially from the collision slot until we encounter the first slot that is empty.
What is linear probing?
Systematically visiting each slot one at a time.
What is a disadvantage of linear probing?
Clustering - the tendency for items to become clusters in the hash table.