0% found this document useful (0 votes)
58 views3 pages

Static and Dynamic Hashing

Static hashing involves storing dictionary pairs in a hash table divided into buckets, with each bucket holding a limited number of pairs determined by a hash function. The loading density of the hash table is calculated based on the number of pairs and the total possible keys, while dynamic hashing adjusts the size of the hash table when the loading density exceeds a threshold. Both methods aim to optimize the efficiency of insert, delete, and search operations, with dynamic hashing providing solutions to overflow issues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

Static and Dynamic Hashing

Static hashing involves storing dictionary pairs in a hash table divided into buckets, with each bucket holding a limited number of pairs determined by a hash function. The loading density of the hash table is calculated based on the number of pairs and the total possible keys, while dynamic hashing adjusts the size of the hash table when the loading density exceeds a threshold. Both methods aim to optimize the efficiency of insert, delete, and search operations, with dynamic hashing providing solutions to overflow issues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Static Hashing

•​ In static Hashing , dictionary pairs are stored in a table ht, called the hash table.
•​ Hash table is partitioned into b buckets ht[0],…ht[b-1].
•​ Each bucket is capable of holding s dictionary pairs.
•​ Bucket consist of s slots each slot being large enough to hold one dictionary pair.
•​ Usually s=1, and each bucket can hold exactly one pair
•​ The address or location of a pair whose key is k is determined by a hash function h- which maps keys into
buckets. Thus for any key k, h(k) is an integer in the range 0- (b-1)
•​ Key density of a hash table is the ratio n/T, where n- no of pairs in the table, T- total no of possible keys
•​ The loading density or loading factor of a hash table is = n/(sb)
•​ Key density of a hash table is the ratio n/T,
•​ where n- no of pairs in the table ,T- total no of possible keys.
•​ The loading density or loading factor of a hash table is = n/(sb)
Example: f the keys are at most 6 characters long, where each character may be a decimal digit or an uppercase
letter and the first char is a letter No of possible keys T= 26X36i >1.6 X109
Example
• Consider a hash table ht with b=26 buckets and s=2. we have n=10 distinct identifiers each representing C library
function.
• Load factor=10/52=0.19
• The hash function must map each of the possible identifiers onto one of the nos 0-25
• Construct a simple hash function by associating letters a-z with no’s 0-25 respectively and then defining hash function
f(x) as first character of x

In the above example, if the next identifier clock hashes into bucket ht[2].
•​ Since bucket is full, we have an overflow and we need to resolve it When no overflow occurs, time required to
insert, delete or search using hashing depends only on time required to compute hash function and time to search
one bucket.
•​ Hence insert, delete and search times are independent of n, no of entries in Dictionary Since the bucket size s is
small search within a bucket is carried out sequentially
•​ The above hash function is not well suited because of large no of collisions and overflow.
•​ Choose a hash function that is both easy to compute and results in very few collisions

Dynamic Hashing (Extendible hashing)


To ensure good performance, it is necessary to increase the size of hash table whenever its loading density exceeds a
prespecified threshold.
Example:
If we have b buckets in HT and using division hash function with divisor D=b, then when an insert causes the loading
density to exceed the prespecified threshold,we use array doubling to increase the no of buckets to 2b+1 and also
divisor =2b+1
Two types:
-Dynamic hashing using directories
-Dynamic hashing without directories
Both forms use a hash function h that maps keys into non negative integers

k h(k)
A0 100 000
A1 100 001
B0 101 000
B1 101 001
C1 110 001
In this example
keys are 2 C2 110 010 characters
each char C3 110 011 transforms
into 3 bit sequence
A-100
C4 110 101 B-101
C-110
Each did=git 0-7 is represented by 3 bit sequence H(A0,1)=0=0
H(A1,3)=001=1 H(B1,4)=1001=9

You might also like