



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Reading: Ford&Topp, Chapter 12 through Section 12.5.
Some container operations in the standard library include a find operation within the insert or erase function.
Answering these two questions will be the focus of the rest of our discussion on hashing.
Hashing may be used in place of balanced binary search trees when ordering of the keys is not required.
unsigned int hash( string const& k, unsigned int N ); { unsigned int value = 0; for ( unsigned int i=0; i<k.size(); ++i ) value += k[i]; // conversion to int is automatic return k % N; }
The problem is that different permutations of the same string result in the same hash table location.
unsigned int hash( string const& k, unsigned int N ); { unsigned int value = 0; for ( unsigned int i=0; i<k.size(); ++i ) value = value*8 + k[i]; // conversion to int is automatic return k % N; }
Two classes of approaches to collision resolution are commonly used:
(i+1)%N, (i+2)%N, (i+3)%N, ...
until an empty location is found.
(i+1)%N, (i+22)%N, (i+33)%N, (i+4*4)%N, ...
More generally, the jth^ “probe” of the table is
(i + c 1 j + c 2 j^2 ) mod N
where c 1 and c 2 are constants.