10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4. Rehashing<br />

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

Hash2 (Key) = R ‐ (Key % R) where R is a prime number smaller than the hash<br />

table size.<br />

If the table gets too full, the running time for the operations will start taking too<br />

long and inserts might fail with quadratic probing.<br />

The standard solution in this case is to build an entirely new hash table<br />

approximately twice the size of the original, calculate a new hash value for each<br />

key and then insert all keys into the new table (then destroying the old table).<br />

This is known as reorganization or rehashing.<br />

HASHING ALGORITHMS<br />

Hashing is a technique in which a given key field value is converted in to address<br />

of a storage location of the record by applying some operations on it.This<br />

technique is very useful for creatingand <strong>using</strong> random file organisation.<br />

A number of hash techniques are available.some examples of hashing<br />

algorithms are as follows:<br />

<strong>1.</strong> Method of division:In this method the key field value is divided by some<br />

suitable number (a prime number) so that quotient can be used as the<br />

address of the record.e.g.key field value 210 can be divided by 13 to<br />

obtain quotient 16 as address of the record.<br />

2. Division/Remainder Method:In this method key field value is divided by<br />

appropriate integer and the remainder is used as the relative address<br />

for the record. e.g. a file having 90 records with primary key values<br />

between 300 to 5000.let the divisor be 97.Then if the key values are<br />

600,1082,1540,the remainder after divison by 97 are 18,15 and 85<br />

respectively.common practice is to add 1 to the remainder.hence relative<br />

address are 19,16 & 86 respectively.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 27 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!