0% found this document useful (0 votes)
3 views6 pages

Hashing

Hashing is a technique that maps data of arbitrary size to fixed-size values for efficient data retrieval using a hash function. It involves storing key-value pairs in a hash table, where a hash code determines the index, and collisions can occur when different keys produce the same hash code. Various collision resolution techniques, such as separate chaining and open addressing, are employed to maintain performance, with the analysis of hashing algorithms focusing on time and space complexity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Hashing

Hashing is a technique that maps data of arbitrary size to fixed-size values for efficient data retrieval using a hash function. It involves storing key-value pairs in a hash table, where a hash code determines the index, and collisions can occur when different keys produce the same hash code. Various collision resolution techniques, such as separate chaining and open addressing, are employed to maintain performance, with the analysis of hashing algorithms focusing on time and space complexity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Hashing

Hashing is a technique used to map data of arbitrary size to fixed-size values, usually for the purpose of
fast data retrieval. The process involves using a hash function to convert an input (or 'key') into a hash
code (or 'hash value'), which typically is an integer. This hash code is then used as an index to store the
actual data in a hash table

 Hash Function: A function that takes an input (or 'key') and returns a hash code. The goal of a
good hash function is to distribute hash codes uniformly across the hash table to minimize
collisions.

Types of Hash Functions:

 Hash Table: A data structure that stores key-value pairs. The hash code determines the index
in the hash table where the data associated with a given key is stored.

 Collisions: Occur when two keys produce the same hash code. Handling collisions efficiently
is crucial for maintaining the performance of a hash table.
Collision Resolution Techniques:

1. Separate Chaining /Closed Addressing/open Hashing: Each index in the hash table
points to a linked list of entries that share the same hash code. This method allows
multiple entries to be stored at the same index.
2. Open Addressing/Closed Hashing: When a collision occurs, the algorithm probes the
hash table to find an empty slot. There are several probing methods:
o Linear Probing: Check the next slot sequentially until an empty slot is found.
o Quadratic Probing: Use a quadratic function to determine the next slot.
o Double Hashing: Use a second hash function to determine the probe sequence.

Linear Probing Quadratic Probing Double Hashing


Example by Division Hash Function:
Multiplication Method
Linear Probing Example

Hash Table

92
43

35
36
27
18
45
Load Factor:

Analysis of Hashing Algorithms

The performance of hashing algorithms is typically analyzed in terms of:

 Time Complexity:
o Average-case: O (1) for insertion, deletion, and search if the hash function
distributes keys uniformly and the load factor (ratio of number of entries to table
size) is low.
o Worst-case: O (n) in cases of many collisions or poor hash function performance.
 Space Complexity: Dependent on the size of the hash table and any additional data
structures used for collision resolution (e.g., linked lists in chaining).

You might also like