Open In App

Hashing in Data Structure

Hashing is a fundamental data structure that efficiently stores and retrieves data in a way that allows for quick access. It involves mapping data to a specific index in a hash table using a hash function that enabling fast retrieval of information based on its key. This method is commonly used in databases, caching systems, and various programming applications to optimize search and retrieval operations.

Hashing Data Structure

What is Hashing in Data Structure?

Hashing is a technique used in data structures to store and retrieve data efficiently. It involves using a hash function to map data items to a fixed-size array which is called a hash table.

Hash Table in Data Structure

A hash table is also known as a hash map. It is a data structure that stores key-value pairs. It uses a hash function to map keys to a fixed-size array, called a hash table. This allows in faster search, insertion, and deletion operations.



Hash Function

The hash function is a function that takes a key and returns an index into the hash table. The goal of a hash function is to distribute keys evenly across the hash table, minimizing collisions (when two keys map to the same index).

Common hash functions include:

What is a Hash Collision?

A hash collision occurs when two different keys map to the same index in a hash table. This can happen even with a good hash function, especially if the hash table is full or the keys are similar.

Causes of Hash Collisions:

Collision Resolution Techniques

There are two types of collision resolution techniques:

  1. Open Addressing:
    • Linear Probing: Search for an empty slot sequentially
    • Quadratic Probing: Search for an empty slot using a quadratic function
  2. Closed Addressing:
    • Chaining: Store colliding keys in a linked list or binary search tree at each index
    • Cuckoo Hashing: Use multiple hash functions to distribute keys

Applications of Hashing

Hash tables are used in a wide variety of applications, including:

Basics of Hashing in Data Structure:

Easy Problem on Hashing:

Medium Problem on Hashing:

Hard Problem on Hashing:

Quick Links :

Recommended:


Article Tags :