Separate Chaining: Concept, Advantages & Disadvantages

Instructor: Lyna Griffin

Lyna has tutored undergraduate Information Management Systems and Database Development. She has a Bachelor's degree in Electrical Engineering and a Masters degree in Information Technology.

In this lesson, we will learn the technique called separate chaining as a solution to data collision occurrences. We will learn how collisions occur in the traditional hash table data structure and how separate chaining helps resolve this.

What is Separate Chaining?

There are many types of data access and searching mechanisms that govern our applications and database. These include various algorithms and binary search trees. Binary search trees are integrated into algorithms to improve the efficiency of search operations. In this lesson, we introduce another data structure called the hash table which has made the efficiency of search operations even better.

A hash table, a data structure that maps keys to values, has two parts, the actual table where the data is stored, and the hash function used to map the index keys to values. In normal operations, the hash table evaluates input data and then assigns an index key (table location) to that value. Now, when two different keys hash to the same index in a hash table a collision is said to have occurred. Memory is limited, and systems would need an incredible amount of memory for collisions not to occur. Collisions are generally evenly distributed around the hash table. This means that no single position on the hash table will be unduly overwhelmed with a long list of collisions compared to other locations within the table.

To handle collisions the hash table has a technique known as separate chaining. Separate chaining is defined as a method by which linked lists of values are built in association with each location within the hash table when a collision occurs. Figure 1 shows incidences of collisions in different table locations. We will assign strings as our input data: [John, Janet, Mary Martha, Claire, Jacob, and Philip]. Our hash table size is 6. As the strings are evaluated at input through the hash functions, they are assigned index keys (0, 1, 2, 3, 4, or 5). We store the first string John, then Janet and Mary. All is fine, but when we try to store Martha, the hash function assigns Martha the same index key as Janet. Now, because a second value is attempting to map to an already occupied index key, a collision occurs as seen in Figure 1. Three out of the six locations are occupied and the probability that the remaining strings yet to be loaded will cause other collisions is very high.



The concept of separate chaining involves a technique in which each index key is built with a linked list. This means that the table's cells have linked lists governed by the same hash function. So, in place of the collision error which occurred in Figure 1, the cell now contains a linked list containing the string 'Janet' and 'Martha' as seen in Figure 2. We see how the subsequent strings are loaded using the separate chaining technique.

separate chaining


Simple to Implement

Separate chaining is a very simple technique to implement compared to other data structures. Input elements are just added to the corresponding linked list which the input has been hashed to. No collision occurs in the table as the cells hold linked information.

Hash Table Capacity Not Limited

There is no issue with the table being filled to capacity, as the table cells only hold linked information. New elements are just added to the corresponding chain.

Robust Technique

Separate chaining is less vulnerable to issues with poor hash functions and factors that affect input loading. The link system eliminates overloads and collisions.

Accommodates Many Keys

This technique is particularly useful when the volume of the input data and the frequency with which the hash keys are generated and re-assigned are not known.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 160 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account