Lecture 3.Pptx 3
Lecture 3.Pptx 3
Facilitator : Dr.S.Saraswathi
HASH TABLE
• Hash Table is a data structure which stores data in an associative manner.
• In a hash table, data is stored in an array format, where each data value
has its own unique index value.
• Access of data becomes very fast if we know the index of the desired data.
• Hash Table uses an array as a storage medium and uses hash technique to
generate an index where an element is to be inserted or is to be located
from.
• A Hash Function is a function that converts a given numeric or
alphanumeric key to a small practical integer value.
• Consider an example of hash table of size 20, and the following items are to
be stored. Item are in the (key,value) format.
(2,70)
(42,80)
(4,25)
(12,44)
(14,32)
(17,11)
(13,78)
• Define a data item having some data and key, based on which the
search is to be conducted in a hash table.
• struct DataItem
{
int data;
int key;
};
Hash Method
• Define a hashing method to compute the hash code of the key of the
data item.
• i. Linear Probing
• ii. Quadratic Probing
• iii. Double hashing
Linear Probing
• The hashing technique is used to create an already used index of the
array.
• In such a case, we can search the next empty location in the array by
looking into the next cell until we find an empty cell.
Division Method
If k is a key and m is the size of the hash table, the hash
function h() is calculated as:
h(k) = k mod m
• where,