This document provides an introduction to hashing and hash tables. It defines hashing as a data structure that uses a hash function to map values to keys for fast retrieval. It gives an example of mapping list values to array indices using modulo. The document discusses hash tables and their operations of search, insert and delete in O(1) time. It describes collisions that occur during hash function mapping and resolution techniques like separate chaining and linear probing.
INTRODUCTION
Hashing is animportant Data Structure which is
designed to use a special function called the Hash
function which is used to map a given value with a
particular key for faster access of elements. The
efficiency of mapping depends on the efficiency of the
hash function used.
3.
FOR EXAMPLE:-
Leta hash function H(x) maps the value at the
index x%10 in an Array. For example if the list of
values is [11,12,13,14,15] it will be stored at positions
{1,2,3,4,5} in the array or Hash table respectively.
HASH TABLE
A hashtable is a data structure that stores elements and
allows insertions, lookups, and deletions to be performed in
O(1) time.
A hash table is an alternative method for representing a
dictionary.
6.
Hash Table Operations
–Search: Compute f(k) and see if a pair exists.
– Insert: Compute f(k) and place it in that position.
– Delete: Compute f(k) and delete the pair in that
position.
NOTE:- In ideal situation, hash table search, insert or
delete takes O(1).
7.
COLLISION
When the hashvalue of a key maps to an already
occupied bucket of the hash table,
it is called as a Collision.
9.
SEPARATE CHAINING
Tohandle the collision,
This technique creates a linked list to the slot for which
collision occurs.
The new key is then inserted in the linked list.
These linked lists to the slots appear like chains.
That is why, this technique is called as separate chaining
LINEAR PROBING
Thelinear probing hash table is a fairly simple
structure where data items are stored directly inside
the hash element array. It gets its name by the way
it handles the unique problems that exist when
storing the data items in the table directly.