Documente Academic
Documente Profesional
Documente Cultură
EECS 215
Hash Tables
Another kind of Table O(1) on average for insert, lookup, and remove use an array named T of size `capacity` define a hash function that returns an integer int hash(string key, int N) must return an integer between 0 and N-1 store the key and info at T[hash(key, capacity)] hash() must always return the same integer for a given key
Table Size
Table size is usually prime to avoid bias Overly large table size means wasted space Overly small table size means more collisions What happens as table size approaches 1?
Hash Functions
a good hash function has the following characteristics avoids collisions spreads keys evenly in the array inexpensive to compute - must be O(1)
Perfect Hashing
when set of keys is known beforehand EG a set of reserved words for a programming language we can construct a function that guarantees no collisions called `Perfect Hashing' but may require more than N slots in the table a `Minimal Perfect Hash Function` uses exactly N slots