




























































































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!





























































































7/7/2012 Hashing 5-
EE 232 Data Structures Session-05 , Spring-
7/7/2012 Hashing 5-
Let us assume that we want to search for a particular item in a database of 20,000,000 data items How long would it take to find for a successful search? How long would it take for an unsuccessful search?
It depends on the data structure
7/7/2012 Hashing 5-
7/7/2012 Hashing 5-
Our goals: We will
See several methods of implementing the hash table Compare these methods analytically Show numerous applications of hashing Compare hash tables with binary search trees
7/7/2012 Hashing 5-
7/7/2012 Hashing 5-
The general idea behind hashing is to directly map each data item into an address in memory using some function key hash function index to an array
Components of hashing A hash table is an array of some fixed size ‘m’ A hash function h(k) that maps a search key k to some location in the range [0...m-1]
7/7/2012 Hashing 5-
Desired Properties of h(k) simple to compute uniform distribution of keys over {0, 1, …, m-1}
7/7/2012 Hashing 5-
m-
Name: Kashif Javed University: UET Office: room 4 EED Mobile Number: Email: etc
Data Items
h(Javed) = 1
Name: Hassan Hamid University: UET Office: room 8 EED Mobile Number: Email: etc
h(Hamid) = 1
A collision has occurred
array
7/7/2012 Hashing 5-
Hashing revisited A hash table data structure is an array Each data element contains a key Each key is mapped to some number in the range from 0 to TableSize-1, with the help of a hash function
7/7/2012 Hashing 5-
Example PTCL is a large telephone company, and they want to maintain a database that provides the caller ID capability
7/7/2012 Hashing 5-
Solution 2 Linked list
Umer Hamid 6829227
Hassan Hamid 6829229
7/7/2012 Hashing 5-
Solution 3 Hash table
(null) (null) (null) (null) Hassan Hamid 0 1 2 3 4
7/7/2012 Hashing 5-
A simple hash function If input keys (k) are integers hash function, h( k ) = k mod m
Example
7/7/2012 Hashing 5-
Another simple hash function If input keys (k) are integers hash function, h( k ) = k mod m
Example