Dat Astruc T Hashing Rep
Dat Astruc T Hashing Rep
Dat Astruc T Hashing Rep
Data Structure
By: Andre L. Marquez
Hashing Definiton
There are several types of hashing algorithms, each with its own unique characteristics and
strengths. Here are some common types of hashing:
Division hashing
Multiplication hashing
Universal hashing
Cryptographic hashing
Perfect hashing
Division Hashing
Division hashing is a simple hashing technique in which the hash code for
an input key is obtained by taking the remainder of the key divided by the
table size.
In other words, given a key k and a table of size m, the hash function h(k)
for division hashing is defined as:
h(k) = k % m
where the % symbol represents the modulo operator, which returns the
remainder of the division.
This method is easy to implement and can work well for many
applications, but it has some limitations. One potential issue is that if the
table size is not chosen carefully, it can lead to many collisions, which
can slow down the performance of the hash table. Additionally, it can be
vulnerable to attacks, such as intentional collisions, if an attacker knows
the hash function being used.
Multiplication Hashing
Multiplication hashing is a technique used in hashing that involves
multiplying the input key by a constant and then using the fractional part
of the product to obtain a hash code.
where k is the input key, m is the size of the hash table, A is a constant
between 0 and 1, and floor() is the floor function.
Multiplication hashing can work well for many applications, and it has
the advantage of producing a more even distribution of hash codes than
division hashing. However, it can be more computationally expensive
than division hashing due to the multiplication operation. Additionally,
choosing an appropriate constant value can be difficult and requires some
trial and error.
Universal Hashing
Universal hashing is a technique used in hashing that provides a way
to select a hash function at random from a family of hash functions.
The goal of universal hashing is to minimize the number of
collisions in a hash table, even when the input data is not known in
advance.
A family of hash functions is said to be universal if, for any two
distinct keys, the probability that they collide when hashed with a
randomly chosen hash function from the family is at most 1/m,
where m is the number of slots in the hash table. In other words, the
probability of a collision is very low for any pair of keys, no matter
what their values are.
To achieve this, universal hashing uses a hash function that is
selected at random from a family of hash functions, rather than
using a fixed hash function. This means that the hash function used
for a given key is not predetermined but is chosen at runtime. By
selecting the hash function randomly, the likelihood of collisions can
be minimized, even when the input data is not known in advance.
Universal hashing can be used with various collision resolution
techniques, such as chaining or open addressing, to create efficient
hash tables that provide fast access to data.
Cryptographic Hashing
In a perfect hash table, the time required to search for an item is constant and
independent of the size of the table. This makes perfect hashing ideal for
applications where the set of keys is known in advance and is relatively static.
1.Staticperfect hashing: This approach is used when the set of keys is known
in advance and is fixed. A static perfect hash function is created by
precomputing all possible hash functions and selecting the one that results in
no collisions.
2.Dynamic perfect hashing: This approach is used when the set of keys can
change over time. A dynamic perfect hash function is created by first
generating a hash function that may produce collisions, and then using a
secondary hash table to resolve any collisions that occur.
3. ______:This is the simplest form of hashing, in which the key is divided by the table
size, and the remainder is used as the hash code.
4. ______:This is a family of hash functions that are designed to minimize the number of
collisions. The hash function is chosen randomly from a family of functions, which ensures
that no particular set of keys will cause a large number of collisions.
2. Perfect Hashing :This is a special type of hashing that guarantees no collisions will occur.
3. Division Hashing :This is the simplest form of hashing, in which the key is divided by the
table size, and the remainder is used as the hash code.
4. Universal Hashing :This is a family of hash functions that are designed to minimize the
number of collisions. The hash function is chosen randomly from a family of functions, which
ensures that no particular set of keys will cause a large number of collisions.
5. Multiplication Hashing :This type of hashing uses a multiplication operation to generate a hash
code.