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.

COLLISION<br />

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

When inserting an element, if it hashes to the same value as an already inserted<br />

element, then we have a collision and need to resolve it. There are two popular<br />

methods:<br />

<strong>1.</strong>Open Addressing<br />

2.Chaining<br />

Open Addressing<br />

<strong>1.</strong> Linear Probing<br />

In linear probing, when a collision occurs, the new element is put in the next<br />

available spot (by doing a sequential search).<br />

For example:<br />

Insert : 49, 18, 89, 48, Hash table size = 10, so<br />

49 % 10 = 9,<br />

18 % 10 = 8,<br />

89 % 10 = 9,<br />

48 % 10 = 8<br />

The problem with linear probing is that records tend to get clustered around<br />

each other. i.e. once an element is placed in the hash table the chances of it’s<br />

adjacent element being filled are doubled (i.e. it can either be filled by a<br />

collision or directly).<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!