From dd7706630d43c3a8ee60edbdd791c0fbabcacde1 Mon Sep 17 00:00:00 2001 From: Si Lam Date: Sat, 1 Oct 2022 18:14:40 -0500 Subject: [PATCH 1/4] Enter logic for Quadratic hashing --- data_structures/hashing/quadratic_probing.py | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index 0930340a347f..befd379f8877 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -1,3 +1,26 @@ + +""" +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. + +""" #!/usr/bin/env python3 from .hash_table import HashTable From e78d7e78a22141ce1000da5f95834df34dbb8122 Mon Sep 17 00:00:00 2001 From: Si Lam Date: Sun, 2 Oct 2022 07:16:45 -0500 Subject: [PATCH 2/4] Fix shebang on the first line --- data_structures/hashing/quadratic_probing.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index befd379f8877..6711fbbec6e3 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -1,4 +1,4 @@ - +#!/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. @@ -21,7 +21,6 @@ This process is repeated for all the values of i until an empty slot is found. """ -#!/usr/bin/env python3 from .hash_table import HashTable From 514c3066deb87b161329354ed453285b99971e9d Mon Sep 17 00:00:00 2001 From: Si Lam Date: Sun, 2 Oct 2022 07:19:11 -0500 Subject: [PATCH 3/4] Clean up --- data_structures/hashing/quadratic_probing.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index 6711fbbec6e3..e11365129ca9 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -19,9 +19,7 @@ 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 From 6fb40a3c3b77b1234f81bcbecf2411f497ee3e0e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 17:35:29 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/hashing/quadratic_probing.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index e11365129ca9..307599ef6dd5 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -1,15 +1,15 @@ #!/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. +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. +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. +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