Time complexity of linear search
O(n)
Time complexity of hash table search
O(1)
Time complexity of binary search
O(logn)
For a hash table, a perfect hash function should:
Takes an input key of any length
Returns an output hash index of fixed size
For a hash table, a hash index should be:
Unique to the key
Same for equal keys
For a hash table, a key should be:
Immutable (so that its hashed index is always the same)
Name 2 collision resolution methods for hashtable
Separate chaining, linear probing (open addressing)
What is hashing?
Hashing is the process of calculating the address (index) of a piece of data from its key using a hash function
The key steps for Binary Search are:
l = 0 and r = array.length-1midmid: if match, return mid; if less than key, update r to mid-1; if greater than key, update l to mid+1l==r (and no match found), return none or raise error, else repeat from step 3The key steps for Linear Search are:
Time complexity of hash table removal
O(1)
Time complexity of hash table insertion
O(1)