Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of Open hashing and Closed hashing

Tags:

hash

Open Hashing (Separate Chaining):

In open hashing, keys are stored in linked lists attached to cells of a hash table.

Closed Hashing (Open Addressing):

In closed hashing, all keys are stored in the hash table itself without the use of linked lists.

I am unable to understand why they are called open, closed and Separate. Can some one explain it?

like image 309
hareendra reddy Avatar asked Feb 03 '12 05:02

hareendra reddy


People also ask

What do you mean by closed and open hashing?

In open hashing, keys are stored in linked lists attached to cells of a hash table. Closed Hashing (Open Addressing): In closed hashing, all keys are stored in the hash table itself without the use of linked lists.

What is meant by open hashing?

Open hashing or separate chaining. Open hashing is a collision avoidence method which uses array of linked list to resolve the collision. It is also known as the separate chaining method (each linked list is considered as a chain).

What is the other name of open hashing?

Open Hashing (Separate Chaining) In open hashing, keys are stored in linked lists attached to cells of a hash table.

What is a closed hash table?

Also known as closed hashing. Also known as open hashing. Collisions are dealt with by searching for another empty buckets within the hash table array itself. A key is always stored in the bucket it's hashed to.


3 Answers

The use of "closed" vs. "open" reflects whether or not we are locked in to using a certain position or data structure (this is an extremely vague description, but hopefully the rest helps).

For instance, the "open" in "open addressing" tells us the index (aka. address) at which an object will be stored in the hash table is not completely determined by its hash code. Instead, the index may vary depending on what's already in the hash table.

The "closed" in "closed hashing" refers to the fact that we never leave the hash table; every object is stored directly at an index in the hash table's internal array. Note that this is only possible by using some sort of open addressing strategy. This explains why "closed hashing" and "open addressing" are synonyms.

Contrast this with open hashing - in this strategy, none of the objects are actually stored in the hash table's array; instead once an object is hashed, it is stored in a list which is separate from the hash table's internal array. "open" refers to the freedom we get by leaving the hash table, and using a separate list. By the way, "separate list" hints at why open hashing is also known as "separate chaining".

In short, "closed" always refers to some sort of strict guarantee, like when we guarantee that objects are always stored directly within the hash table (closed hashing). Then, the opposite of "closed" is "open", so if you don't have such guarantees, the strategy is considered "open".

like image 166
Ken Wayne VanderLinde Avatar answered Oct 04 '22 09:10

Ken Wayne VanderLinde


The name open addressing refers to the fact that the location ("address") of the element is not determined by its hash value. (This method is also called closed hashing).

In separate chaining, each bucket is independent, and has some sort of ADT (list, binary search trees, etc) of entries with the same index. In a good hash table, each bucket has zero or one entries, because we need operations of order O(1) for insert, search, etc.

This is a example of separate chaining using C++ with a simple hash function using mod operator (clearly, a bad hash function)

like image 40
D. Pérez Avatar answered Oct 04 '22 07:10

D. Pérez


You have an array that is the "hash table".

In Open Hashing each cell in the array points to a list containg the collisions. The hashing has produced the same index for all items in the linked list.

In Closed Hashing you use only one array for everything. You store the collisions in the same array. The trick is to use some smart way to jump from collision to collision until you find what you want. And do this in a reproducible / deterministic way.

like image 33
Anton Andreev Avatar answered Oct 04 '22 07:10

Anton Andreev