Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

PAMANTASAN NG LUNGSOD NG MUNTINLUPA

NBP Reservations, Poblacion Muntinlupa City

Hashing:
Quadratic Probing
Research Title

Presented by:
Lord Edgardian J. Tavu
Demwell Demabasa
Reggie Manuguid
Red Sarmiento

Quadratic Probing
Quadratic Probing eliminates primary clustering
problem of linear probing.
Collision function is quadratic.
The popular choice is f(i) = i2.
If the hash function evaluates to h and a search in
cell h is inconclusive, we try cells h + 12, h+22, h
+ i2.
i.e. It examines cells 1,4,9 and so on away from the
original probe.

Remember that subsequent probe points are a


quadratic number of positions from the original
probe point.

Quadratic Probing
Problem:
We may not be sure that we will probe all locations
in the table (i.e. there is no guarantee to find an
empty cell if table is more than half full.)
If the hash table size is not prime this problem will
be much severe.

However, there is a theorem stating that:


If the table size is prime and load factor is not
larger than 0.5, all probes will be to different
locations and an item can always be inserted.

Theorem
If quadratic probing is used, and the table size is
prime, then a new element can always be inserted
if the table is at least half empty.

Quadratic Probing

for 47:
47%7 = 5
Probe sequence:
i=0, (5+0) % 7 = 5
i=1, (5+1) % 7 = 6
i=2, (5+4) % 7 = 2
i=3, (5+9) % 7 = 0
i=4, (5+16) % 7 = 0
i=5, (5+25) % 7 = 2

Quadratic Probing

Some Considerations:
How efficient is calculating the quadratic probes?
Linear probing is easily implemented. Quadratic
probing appears to require * and % operations.
However by the use of the following trick, this is
overcome:
Hi = Hi-1+2i 1 (mod M)
What happens if load factor gets too high?
Dynamically expand the table as soon as the load
factor reaches 0.5, which is called rehashing.
Always double to a prime number.

When expanding the hash table, reinsert the new


table by using the new hash function.

Quadratic Probing
for
for 5:
48:
5
48%%7 7==5 5
Probe
Probe sequence:
sequence:
i=1,
i=1, (5+1)
(6+1) %
%7
7
=
=0
0
i=2, (5+4) % 7
=2
for 55:
55 % 7 = 6
Probe sequence:
I=1, (6+1) % 7 = 0
i=2, (6+4) % 7 = 3

Analysis of Quadratic Probing


Quadratic probing has not yet been mathematically
analyzed.
Although quadratic probing eliminates primary
clustering, elements that hash to the same location
will probe the same alternative cells. This is known
as secondary clustering.
Techniques that eliminate secondary clustering are
available.
the most popular is double hashing.

Quadratic Probing

Researcher:
Leader:
Lord Edgardian Tavu
Member:
Reggie Manuguid
Demwell Demabasa
Red Angelo Sarmiento

Quadratic Probing

Supplementary Exercise
1. What is the formula for quadratic probing?
2. What is the theorem of quadratic probing?
3. What does quadratic probing do with linear probing?
4. What happens if load factor gets too high?
5. What operations did quadratic probing requires?
6. Can quadratic probing eliminate secondary clustering?
7. If the table size is prime, and it is at least half empty, can we
add a new element?
8. What do you call to the load section of the table?
9. What do you call to the elements loaded to the table?
10. What is the most popular method to eliminate secondary
clustering?
11-20. Insert the load factors to the table using Quadratic
Probing Hash
Method.

Quadratic Probing
Supplementary Text
1. The formula is f(i) = i2.
2. If quadratic probing is used, and the table size is prime, then
a new element can always be inserted if the table is at least
half empty.
3. Quadratic Probing eliminates primary clustering problem of
linear probing.
4. Dynamically expand the table as soon as the load factor
reaches 0.5, which is called rehashing.
5. Quadratic probing appears to require * and % operations.
6. Yes, if the table size is prime.
7. If the table size is prime and load factor is not larger than
0.5, all probes will be to different locations and an item can
always be inserted.
8. Cell
9. Load Factor
10. double hashing

11-20.

You might also like