Hash Table
Hash Table
Implementation
use an array of linked list and a hash code function
To insert a key
Compute key's hash code(a integer)
Compute the index in the array with the hash code(could be done with has(key) % array_length)
Use the index, we can find our linked list(using linked list because there could have 2 different keys with the same hash code)
To retrieve the value through key, we search through the linked list on that index
If the number of collision is very high, then the worst case is O(n), n is the number of key
Generally look up time is O(1)
Last updated
Was this helpful?