Time complexity of linear search
O(n)
Time complexity of binary search
O(log n)
Time complexity of hash table search
Without collision resolution: O(1)
With collision resolution: O(n)
For a hash table, a hash function should:
Returns an output hash index of fixed size
For a hash table, a key should be:
Immutable (so that its hashed location is always the same)
Features of an ideal hash function
The key steps for Binary Search are:
start = 0 and end = array.length - 1midmid:midend to mid - 1start to mid + 1start > end (no match found), return none or display/raise error, else repeat from step 3collision resolution
open addressing (generation of new location):
1. hash key to location
2. if key matches store key and value pair at location
3. else, rehash key to new location and repeat step 2
4. if no more location available return error
close addressing (each location in the table is a linked list):
1. hash key to location
2. check if linked list at location have the key (yes, end/ update)
3. else, add key-pair value to end of linked list