Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

hash tables
data structures

What is chaining in hash tables?

Educative Answers Team

Chaining is a technique used for avoiding collisions in hash tables.

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.

svg viewer

The benefits of chaining

  • Through chaining, insertion in a hash table always occurs in O(1) since linked lists allow insertion in constant time.

  • Theoretically, a chained hash table can grow infinitely as long as there is enough space.

  • A hash table which uses chaining will never need to be resized.


hash tables
data structures
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring