We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 21
. Hashing
PEE Basic Concepts in Hashing
fiash Table : Hash table is a dat
‘a structure used for storing and retrieving data
quickly. Every entry in the hash table is made using Hash function
2) Hash Function
. unction is a funetion used to place data in hash table.
. Si y hash function is used to retrieve data from hash table.
he use of hash function is to implement hash table.
For example : Consider hash function as key mod 5. The hash table of size 5.
Step 1
Insert 33, 0
Step 3: insert 25
3 1
junction a y 25 mod 5=0
Step 2: Insert 54
3, Bucket
Hash Table
3) Bucket : The hash function H(key) is used to map several dictionary entries in the
hash table. Each position of the hash table is called bucket.
4) Collision : Collision is situation in which hash function returns the same address
more than one record.
PFor example
example - In above
Overflow :
then it is calledDats Structures and Algorithms ae
For example «
Fig, 1.1.3 Overflow situation
8) Perfect hash function : The perfect hash function is a function
key elements into the hash table with no collisions,
Advantages of perfect hash function
DA perfect hash function with limited
lookup operation.
Dy There is
set of elements can be
no need to apply collision resolution technique.
9) Load factor and load density : Consider the hash table as given below -
Slott Slot2
4 eh
Os a
3
4
D 1
Hash Table
Fig. 1.1.4
.
a be the total number of elements in the tai,
en
‘Tis the total number of posible element,
« Tis
r nt density of hash ay)
ity : The eleme TON bath table ty the ratio
Element ETH? Toad density factor
OF Kash tabi -
n
Load density of load
ee
o =1yctures and Algorithme
pp] Hash Functions
pe elements in hash table,
h function depends upon the r
ypically the divisor is table
ecord 54, 72, 89, 37 is
A
Hash Function
h(key) = recordYétable size.
the key & by a constant A where A is in the
fractional part of kA. beanDate Structures and Abprthme
Multiply this fractional part by m and take the
ove stops can be formulated as
ik) = Lm (kA) |
Fractional part
Auth suggested to tse A = (161808398087
k 7, assume m = 50,
0.61803398987
hik)= 50+ 0.12
=6
hik)=6
7 will be placed at index 6 in hash table.
tage
he choice of m is not critical
EER Extraction
“4 some digits are extracted from the key to form the address
example
uppose first, third and fourth digit from left is selected for hash ke
QO
478 a 478 location in the hash
table of size 1000,
the key can be stored.ep cwres and Algorthms,
shod works in follo
square the key
xiract middle part of the
in the hash table.
chat if the key element is a str
is met
sh table of size of 1000
111) = 783
e two folding techniques
‘nift ii) Fold boundary —
) Fold shift : In this method the
with the size of requiredStructures and Algorithms
Universal Hashing
viversal hashing is a hashing technique in which
‘at function at random, from family of
athematical properties.
_
niversal hashing guarantees lower number of collisio
¢ set of universe keys :
ne finite collection of Hash functions mapping U into
universal if, for x, y EU (x# y)
H
[{h eH: h(x)=h(y)} | = i
“ans, probability of a collision for two different keys x a
1
domly chosen from H is
If his chosen from a universal class of hash functions and
able of size m, where n< m,
the expected number of
Node
¢ element}
KE> **next; setae
sonst pait_type 1 pair,
Element
Fig. 1.7.5
Operations on Skip List
erations that can be performed on skip lists are
g a node from the skip list.
n of a node from skip list.
of a node from skip list.
ching of a Node
for the 'key' node then follow these 3 rules ~
urrent — key then the node is found.
t + key, just go down one level.
key, go right along the link
HNNICAL PUBLICATIONS® - An up thrust for knowledgean peeewet
seer-tiKaey vai)
5 to be Galena
Tey val) |/ sate te ch Grommet