mapping adt Flashcards
(9 cards)
rehashing with dictionary
O(n);
bucket = hash(key) % m;
-# splits keys into m buckets
hash(self, key):
return key % self._n_buckets
rehashing
self._n_buckets *= 2;
new_L = [[] for i in range(self,_n_buckets];
for bucket in self._L;
> for entry in bucket:
» new_bucket = self.hash(entry.key);
»new_L[new_bucket].append(entry)
self._L = new_L[:]
load factor
entries / table size
separate chaining
collisions are resolved by storing all colliding keys in one slot using an ADT like linked list
open addressing / closed hashing
collisions are resolved by storing the colliding key in the next best place
linear probing
solve hash collision by storing the key in the closest following free location
quadratic probing
search for the i^2 bucket in ith iteration
double hashing
use a secondary hash function