Hash Table in Data Structure

Hash Table in Data Structure

Hash Table in Data Structure


A hash table is a data structure which maps keys to values for highly efficient lookup.


There are many ways of implementing a hash table. Here we will see the simple and most common implementation.

Step 0:- Define an array on which values correspond to keys stored.

Step 1:- Using a hash function, generate a unique hash key.

Step 2:- Calculate the index to insert values.

*To avoid Array Index out of bound exception, take modulo of generated hash key with the array length(hash key % array length).

Step 3:- Insert values in a Linked List considering the calculated index as the head. (Don't insert value directly to avoid hash collision)

What is a hash function/hashing?

Hashing is a technique used to identify an object uniquely from a group of similar objects.

No comments:

For Query and doubts!

Powered by Blogger.