Skip to content

Enter logic for Quadratic hashing #6498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion data_structures/hashing/quadratic_probing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#!/usr/bin/env python3

"""
Hashing is a technique that uses a hash function that converts a given number
or any other key to a smaller number and uses the small number as the index in a table called a hash table.

Hash Function:
A function that converts a given big number to a small practical integer value.
The mapped integer value is used as an index in the hash table.

Quadratic Probing:
Quadratic probing is an open-addressing scheme where we look for the i^2th slot in the i’th iteration
if the given hash value x collides in the hash table.

The logic is

For the loop of the array, running from 0 to array length, given x is an element of the array
1 - Check if the slot hash(x) % SizeofHashtable is full, then we try (hash(x) + 1*1) % SizeofHashtable.
2 - then check if (hash(x) + 1*1) % SizeofHashtable is also full, then we try (hash(x) + 2*2) % SizeofHashtable.
3 - then check If (hash(x) + 2*2) % SizeofHashtable is also full, then we try (hash(x) + 3*3) % SizeofHashtable.
...
This process is repeated for all the values of i until an empty slot is found.
"""
from .hash_table import HashTable


Expand Down