An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: Practical Application for Data Structures: Hash Tables

### You're on a roll. Keep up the good work!

Replay
Your next lesson will play in 10 seconds
• 0:04 What Is Separate Chaining?
• 2:07 Concept
• 4:25 Lesson Summary
Save Save

Want to watch this again later?

Timeline
Autoplay
Autoplay
Speed Speed

#### Recommended Lessons for You

Lesson Transcript
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'll learn the technique called separate chaining as a solution to data collision occurrences. We'll 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 databases. 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, which is 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.

The figure shows incidences of collisions in different table locations. We'll 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 we've been using. 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.

## Concept

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 the figure we used in the last section, the cell now contains a linked list containing the string 'Janet' and 'Martha' as seen in this new figure. We can see in this figure how the subsequent strings are loaded using the separate chaining technique.

Let's take a couple of moments to look at the advantages of separate chaining one at a time:

### 1. 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 to which the input has been hashed. No collision occurs in the table as the cells hold linked information.

### 2. Hash Table Capacity Not Limited

There's 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.

To unlock this lesson you must be a Study.com Member.

### Register to view this lesson

Are you a student or a teacher?

#### See for yourself why 30 million people use Study.com

##### Become a Study.com member and start learning now.
Back
What teachers are saying about Study.com

### Earning College Credit

Did you know… We have over 200 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.