0% found this document useful (0 votes)
2 views3 pages

Hashing

Hashing is a technique that maps large data to smaller tables using a hash function, allowing for constant time O(1) retrieval and updates. A hash table stores key-value pairs and uses a hash function to compute indices for data storage, while collisions can occur when multiple keys hash to the same index, which can be resolved through methods like open addressing or chaining. Good hash functions should produce unique hash values, be easy to compute, and minimize collisions.

Uploaded by

poornima.punekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Hashing

Hashing is a technique that maps large data to smaller tables using a hash function, allowing for constant time O(1) retrieval and updates. A hash table stores key-value pairs and uses a hash function to compute indices for data storage, while collisions can occur when multiple keys hash to the same index, which can be resolved through methods like open addressing or chaining. Good hash functions should produce unique hash values, be easy to compute, and minimize collisions.

Uploaded by

poornima.punekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Page |1

Hashing:

Hashing is the process of mapping large amount of data item to smaller table with the help
of hashing function.
Hashing is also known as Hashing Algorithm or Message Digest Function.
It is a technique to convert a range of key values into a range of indexes of an array.
It is used to facilitate the next level searching method when compared with the linear or
binary search.
Hashing allows to update and retrieve any data entry in a constant time O(1).
Constant time O(1) means the operation does not depend on the size of the data.
Hashing is used with a database to enable items to be retrieved more quickly.
It is used in the encryption and decryption of digital signatures.

Hash Table:
Hash table or hash map is a data structure used to store key-value pairs.
It is a collection of items stored to make it easy to find them later.
It uses a hash function to compute an index into an array of buckets or slots from which the
desired value can be found.
It is an array of list where each list is known as bucket.
It contains value based on the key.
Hash table is used to implement the map interface and extends Dictionary class.
Hash table is synchronized and contains only unique elements.

Hash Function:
A fixed process converts a key to a hash key is known as a Hash Function.
This function takes a key and maps it to a value of a certain length which is called a Hash
value or Hash.
Hash value represents the original string of characters, but it is normally smaller than the
original.
It transfers the digital signature and then both hash value and signature are sent to the
receiver. Receiver uses the same hash function to generate the hash value and then
compares it to that received with the message.
If the hash values are same, the message is transmitted without errors.
Page |2

Characteristics of good hashing function


 The hash function should generate different hash values for the similar string.
 The hash function is easy to understand and simple to compute.
 The hash function should produce the keys which will get distributed, uniformly over
an array.
 A number of collisions should be less while placing the data in the hash table.
 The hash function is a perfect hash function when it uses all the input data.

Example:
 The hash table with the size of n = 10. Each position of the hash table is called
as Slot. In the above hash table, there are n slots in the table, names = {0, 1, 2, 3, 4,
5, 6, 7, 8, 9}. Slot 0, slot 1, slot 2 and so on. Hash table contains no items, so every
slot is empty.
 As we know the mapping between an item and the slot where item belongs in the
hash table is called the hash function. The hash function takes any item in the
collection and returns an integer in the range of slot names between 0 to n-1.
 Suppose we have integer items {26, 70, 18, 31, 54, 93}. One common method of
determining a hash key is the division method of hashing and the formula is :

Hash Key = Key Value % Number of Slots in the Table

 Division method or reminder method takes an item and divides it by the table size
and returns the remainder as its hash value.

Data Item Value % No. of Slots Hash Value


26 26 % 10 = 6 6
70 70 % 10 = 0 0
18 18 % 10 = 8 8
31 31 % 10 = 1 1
54 54 % 10 = 4 4
93 93 % 10 = 3 3
Page |3

 After computing the hash values, we can insert each item into the hash table at the
designated position as shown in the above figure. In the hash table, 6 of the 10 slots
are occupied, it is referred to as the load factor and denoted by, λ = No. of items /
table size. For example , λ = 6/10.
 It is easy to search for an item using hash function where it computes the slot name
for the item and then checks the hash table to see if it is present.
 Constant amount of time O(1) is required to compute the hash value and index of
the hash table at that location.

Hash Collision:
It is a situation in which the hash function returns the same hash key for more than one
record, it is called as collision. Sometimes when we are going to resolve the collision it may
lead to a overflow condition and this overflow and collision condition makes the poor hash
function.
Collision Resolution in detail with open addressing & collision resolution by chaining
When one or more hash values compete with a single hash table slot, collisions occur. To
resolve this, the next available empty slot is assigned to the current hash value. The most
common methods are open addressing, chaining, probabilistic hashing, perfect hashing, and
coalesced hashing techniques.

Open Addressing
Like separate chaining, open addressing is a method for handling collisions. In Open
Addressing, all elements are stored in the hash table itself. So at any point, the size of the
table must be greater than or equal to the total number of keys (Note that we can increase
table size by copying old data if needed).

Chaining is a technique
A collision occurs when two keys are hashed to the same index in a hash table. Collisions are
a problem because every slot in a hash table is supposed to store a single element.
The chaining technique
In the chaining approach, the hash table is an array of linked lists i.e., each index has its own
linked list.
All key-value pairs mapping to the same index will be stored in the linked list of that index.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy