rec05 - 6.006 Intro to Algorithms Recitation 05 February...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 6.006 Intro to Algorithms Recitation 05 February 16, 2011 Overview of Hash Tables A hash table is a data structure that supports the following operations: insert(k)- puts key k into the hash table search(k)- searches for key k in the hash table remove(k)- removes key k from the hash table In a well formed hash table, each of these operations take on average O (1) time, making hash tables a very useful data structure. You can think of a hash table as a list of m slots. Inserting a key puts it in one of the slots in the hash table, deleting a key removes it from the slot it was inserted in, and searching a key looks in the slot the key would have been inserted into to see if it is indeed there. Empty slots are designated with a NIL value. The big question is figuring out which slot should a key k be inserted into in order to maintain the O (1) runtime of these operations. Hash Functions Consider a function h ( k ) that maps the universe U of keys (specific to the hash table, keys could be integers, strings, etc. depending on the hash table) to some index 0 to m . We call this function a hash function . When inserting, searching, or deleting a key k , the hash table hashes k and looks at the h ( k ) th slot to add, look for, or remove the key. A good hash function satisfies (approximately) the assumption of simple uniform hashing: each key is equally likely to hash to any of the m slots. The hash function shouldnt bias towards particular slots does not hash similar keys to the same slot (e.g. compilers symbol table shouldnt hash variables i and j to the same slot since they are used in conjunction a lot) is quick to calculate, should have O (1) runtime is deterministic. h ( k ) should always return the same value for a given k 6.006 Intro to Algorithms Recitation 05 February 16, 2011 Example 1: Division method...
View Full Document

This note was uploaded on 11/11/2011 for the course MATH 180 taught by Professor Byrns during the Spring '11 term at Montgomery College.

Page1 / 4

rec05 - 6.006 Intro to Algorithms Recitation 05 February...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online