What is a hash table?
A data structure, typically an array, which contains a set of unique keys, and values associated with these.
What is the main advantage of a hash table?
Data can be retrieved with a constant time complexity of O(1).
What are the steps of the hashing process?
What is a collision?
When the hash function produces the same index for two or more keys.
This is a problem. If multiple items are attempted to be stored I. The same memory location, data will be overwritten.
What are the solutions to dealing with collisions?
Solution 1: Store multiple values at the same index using a linked list.
Solution 2: Use the next available free memory location.
Solution 3: Rehash using a larger table with a different hash function.
What are the steps involved in rehashing?
What are the advantages of hash tables?
Faster to look up/insert a record (O(1)) compared to arrays/linked lists.
Used on large datasets where frequent access/modifications are needed.
What are the disadvantages of hash tables?
Collisions require additional handling.
Data stored is unordered.
Larger amount of memory used due to need for available memory locations.
Do not use if data needs to be sorted e.g. processed in a specific order.