CSC 2200 Chapter Notes - Chapter 5: Hash Function
Chapter 5.1 Hashing
CSC 2200
Hashing
oImplementation of hash tables
oTechnique used for performing insertions, deletions, and finds constant average time
The ideal has table data structure is merely an array of some fixed size containing the items
Chapter 5.2 Hash function
1) int hash( const string & key, int tableSize )
2) {
3) int hashVal = 0;
4)
5) for( char ch : key )
6) hashVal += ch;
7)
8) return hashVal % tableSize;
9) }
Simple Hash function
1) int hash( const string & key, int tableSize )
2) {
3) return ( key[ 0 ] + 27 *key[ 1 ] + 729 * key[ 2 ] ) % tableSize;
4) }
Chapter 5.3 Separate Chaining
Separate chaining
oA strategy to keep a list of all elements that has to the same value
find more resources at oneclass.com
find more resources at oneclass.com