{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes80

# notes80 - CS251 Lecture Notes Feb 21 2005 by Adam...

This preview shows pages 1–3. Sign up to view the full content.

CS251 Lecture Notes - Feb. 21, 2005 by Adam Muehlhausen Last class we went over Hash Tables (called 'chaining') and Probing. -In both chaining and probing hash tables, the expected insertation takes expected time O(1) as long as n is less than N n number of entries N size of hash table In general, the expected time is O(n/N). Hash Functions The function that maps keys to the index in the table is called "hash function". -This is made of 2 parts: hash code map - translates the key to a number. compression map - translates that number to an index (that index will be in the range 0 to N-1) **The Hash Code Map can be 3 things 1) Integer cast- It is used for numeric types and we interpret bits as an int. If the key is already an integer, then the identity function is the hash code map. Example: 2) Component sum- This is used for numbers or variables that use multiple 32 bit words. We add the words in the key. Example: const int MAX = 100; char key[MAX];  //seen as sequence of words in memory //assume key is initialized unsigned int sum = 0; unsigned int * p = (unsigned int *) key; for(int i=0; i < MAX/sizeof(unsigned int); i++) { sum += p[i]; } *You can use this approach for hashing strings. 3) Polynomial accumulation- This function views the words in the key as coefficients of a polynomial ** Compression Map methods 1) Division: h(k) = |f(k)| mod N -most common method. N is usually a prime to give an even distribution

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2) Multiply and divide: h(k) = |a f(k) + b| mod N *sometimes this provides a better distribution. (We will use #1 on project 5 though)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}