CS223 Advanced Data Structures and Algorithms Hashing Neil Tang 02/19/2008 CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Class Overview Basic idea Hashing functions CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Basic Idea Hash table is an array of some fixed size, containing the items. Each item has a key. Hashing is a technique used for performing insertions, deletions and searches in constant average time. Hashing is the implementation of hash tables. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Basic Idea A hash function maps a key into some number in the range [0, TableSize-1]. An ideal hash function can distribute the keys evenly among the cells. Collision (two keys hash to the same value) is the major issue of hashing. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms An Example CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms A Simple Hash Function If TableSize = 10007, the hash function can only assume values [0,127*8]. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Another Hash Function Only 2851 combinations, i.e, only 28% of the table can be hashed to. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms The 3rd Hash Function CS223 Advanced Data Structures and Algorithms