** 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

**that enables fast retrieval of information based on its key. This method is commonly used in databases,**

**hash function****aching systems, and various programming applications to optimize search and retrieval operations.**

**c**Table of Content

## What is Hashing in Data Structure?

** Hashing **is a technique used in data structures to store and retrieve data efficiently. It involves using a

**to map data items to a fixed-size array which is called a**

**hash function****.**

**hash table****How it works:**

You provide your data items into the hash function.**Hash Function:**The hash function crunches the data and give a unique hash code.**Hash Code:**The hash code then points you to a specific location within the hash table.**Hash Table:**

## Hash Table in Data Structure

A ** hash table **is also known as a hash map. It is a data structure that stores

**. It uses a**

**key-value pairs****to map**

**hash function****to a fixed-size array, called a**

**keys****. This allows in faster**

**hash table****,**

**search****, and**

**insertion****operations.**

**deletion**## Hash Function

The** hash function** is a function that takes a

**and returns an**

**key****into the**

**index****. 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).**

**hash table**Common hash functions include:

Key % Hash Table Size**Division Method:**(Key * Constant) % Hash Table Size**Multiplication Method:**A family of hash functions designed to minimize collisions**Universal Hashing:**

## 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:**

A hash function that does not distribute keys evenly across the hash table can lead to more collisions.**Poor Hash Function:**A high load factor (ratio of keys to hash table size) increases the probability of collisions.**High Load Factor:**Keys that are similar in value or structure are more likely to collide.**Similar Keys:**

## Collision Resolution Techniques

There are two types of collision resolution techniques:

**Open Addressing:**Search for an empty slot sequentially**Linear Probing:**Search for an empty slot using a quadratic function**Quadratic Probing:**

**Closed Addressing:**Store colliding keys in a linked list or binary search tree at each index**Chaining:**Use multiple hash functions to distribute keys**Cuckoo Hashing:**

## Applications of Hashing

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

Storing and retrieving data based on unique keys**Databases:**Storing frequently accessed data for faster retrieval**Caching:**Mapping identifiers to their values in programming languages**Symbol Tables:**Determining the best path for data packets**Network Routing:**

**Basics of Hashing in Data Structure**

**Basics of Hashing in Data Structure**

- Introduction to Hashing â€“ Data Structure and Algorithm Tutorials
- What is Hashing?
- Index Mapping (or Trivial Hashing)
- Separate Chaining for Collision Handling
- Open Addressing for Collision Handling
- Double Hashing
- Load Factor and Rehashing

**Easy Problem on Hashing**

**Easy Problem on Hashing**

- Find whether an array is subset of another array
- Union and Intersection of two linked lists
- Given an array A[] and a number x, check for pair in A[] with sum as x
- Maximum distance between two occurrences of same element in array
- Count maximum points on same line
- Most frequent element in an array
- Find the only repetitive element between 1 to n-1
- How to check if two given sets are disjoint?
- Non-overlapping sum of two sets
- Check if two arrays are equal or not
- Find missing elements of a range
- Minimum number of subsets with distinct elements
- Remove minimum number of elements such that no common element exist in both array
- Find pairs with given sum such that elements of pair are in different rows
- Count pairs with given sum
- Count quadruples from four sorted arrays whose sum is equal to a given value x
- Sort elements by frequency
- Find all pairs (a, b) in an array such that a % b = k
- Group words with same set of characters
- k-th distinct (or non-repeating) element in an array.

**Medium Problem on Hashing**

**Medium Problem on Hashing**

- Find Itinerary from a given list of tickets
- Find number of Employees Under every Employee
- Longest subarray with sum divisible by k
- Find the largest subarray with 0 sum
- Longest Increasing consecutive subsequence
- Count distinct elements in every window of size k
- Design a data structure that supports insert, delete, search and getRandom in constant time
- Find subarray with given sum | Set 2 (Handles Negative Numbers)
- Implementing our Own Hash Table with Separate Chaining in Java
- Implementing own Hash Table with Open Addressing Linear Probing in C++
- Minimum insertions to form a palindrome with permutations allowed
- Maximum possible difference of two subsets of an array
- Sorting using trivial hash function
- Smallest subarray with k distinct numbers

**Hard Problem on Hashing**

**Hard Problem on Hashing**

- Clone a Binary Tree with Random Pointers
- Largest subarray with equal number of 0s and 1s
- All unique triplets that sum up to a given value
- Palindrome Substring Queries
- Range Queries for Frequencies of array elements
- Elements to be added so that all elements of a range are present in array
- Cuckoo Hashing â€“ Worst case O(1) Lookup!
- Count subarrays having total distinct elements same as original array
- Maximum array from two given arrays keeping order same
- Find Sum of all unique sub-array sum for a given array.
- Recamanâ€™s sequence
- Length of longest strict bitonic subsequence
- Find All Duplicate Subtrees
- Find if there is a rectangle in binary matrix with corners as 1

**Quick Links :**

- â€˜Practice Problemsâ€™ on Hashing
- Top 20 Hashing Technique based Interview Questions
- â€˜Quizzesâ€™ on Hashing
- â€˜Videosâ€™ on Hashing

**Recommended:**