Log in Sign up
Back to Discover
💻

Hash table

technology Maturity 7-9

Computers use a special list.

Hash table 3 1 1 0 1 0 0 SP.svg
Hash table 3 1 1 0 1 0 0 SP.svg
It helps them find things fast. It works like a phone book. This helps you find what you need. It is very smart! Do you like fast tools?

43 words

Computers use a special list to find things.

Hash table 3 1 1 0 1 0 0 SP.svg
Hash table 3 1 1 0 1 0 0 SP.svg
It works like a phone book. A computer uses a rule to find a spot. This rule turns a name into a number. The number tells the computer where to look. Sometimes, two names want the same spot. This is called a collision. The computer can link the names together in a chain.
Hash table 5 0 1 1 1 1 1 LL.svg
Hash table 5 0 1 1 1 1 1 LL.svg
It can also look for the next empty spot. This helps the computer stay very fast. It is a smart way to store data.

105 words

Computers need fast ways to find data. A hash table is a smart tool for this. It works like a digital dictionary.

A hash table uses a hash function. This is a rule that turns a key into a number. This number is called an index. The index tells the computer which slot to use. The computer stores a value in that slot. This makes finding things very quick.

Sometimes, two different keys get the same index. This is called a collision. Computers have two main ways to fix this. One way is called separate chaining.

Hash table 5 0 1 1 1 1 1 LL.svg
Hash table 5 0 1 1 1 1 1 LL.svg
This method links items together in a chain. The computer follows the chain to find the right one.

Another way is called open addressing.

Hash table 5 0 1 1 1 1 0 SP.svg
Hash table 5 0 1 1 1 1 0 SP.svg
This method looks for the next empty slot.

If a table gets too full, it can slow down. This is measured by the load factor. To stay fast, the computer may resize the table. This is called rehashing. Many programming languages use these tools every day.

194 words

A hash table is a smart way to organize data in a computer. It acts like a digital dictionary or a map.

Hash table 3 1 1 0 1 0 0 SP.svg
Hash table 3 1 1 0 1 0 0 SP.svg
Instead of just making a long list, it uses pairs of information. Each pair has a key and a value. The key is like a name, and the value is the information linked to that name. This structure is very helpful for finding things quickly. Many computer programs use these tables to manage large sets of data.

To make it work, the table uses a hash function. This is a rule that turns a key into a number called an index. This index tells the computer exactly which slot to look in.

Hash table 5 0 1 1 1 1 0 SP.svg
Hash table 5 0 1 1 1 1 0 SP.svg
When you want to find a value, the computer hashes the key first. Then, it goes straight to the correct index to find your answer. This process is very fast. It works well even if the table has many items in it.

Sometimes, a problem called a collision happens. This is when two different keys get the same index number. Computers must have a plan to fix this. One way is called separate chaining.

Hash table 5 0 1 1 1 1 1 LL.svg
Hash table 5 0 1 1 1 1 1 LL.svg
In this method, the computer builds a chain of items in the same slot. It uses a linked list to connect them. Another way is called open addressing.
Hash table 5 0 1 1 1 1 0 LL.svg
Hash table 5 0 1 1 1 1 0 LL.svg
This method searches for the next empty slot in the table instead.

People have been working on these ideas for a long time. In January 1953, Hans Peter Luhn wrote about using hashing with chaining at IBM. Later, researchers like Gene Amdahl and Arthur Samuel used hashing for the IBM 701 assembler. Other experts like A. D. Linh helped develop open addressing. Even the word "hashing" was first published by Robert Morris. These different ideas came together to build the tools we use today.

How well a table works depends on something called the load factor. This is the ratio of stored items to the number of available slots.

Hash table 5 0 1 1 1 1 0 SP.svg
Hash table 5 0 1 1 1 1 0 SP.svg
If the load factor gets too high, the table slows down. To fix this, the computer can resize the table. This new process is called rehashing. Many coding languages like Python and Java have these tools built in. They help programmers use these fast tables without needing to do the hard math themselves.

428 words

A hash table is a fundamental data structure used in computer science to implement an associative array. An associative array is a type of abstract data structure that maps unique keys to specific values. You might know these structures by other names, such as a dictionary or a map.

Hash table 3 1 1 0 1 0 0 SP.svg
Hash table 3 1 1 0 1 0 0 SP.svg
Hash tables are vital because they allow for very efficient data management. They are used widely in software for database indexing, caches, and sets. Many modern programming languages provide these structures built-in. For example, Python uses dictionaries, while Java uses the HashMap. C++ provides the unordered_map, and Go uses maps. These built-in tools handle the complex math of hashing for the programmer.

The mechanism of a hash table relies on a mathematical process called hashing. To store data, the table takes a key and passes it through a hash function. This function computes an index, which is also called a hash code. This index points to a specific location in an array of buckets or slots.

Hash table 5 0 1 1 1 1 0 SP.svg
Hash table 5 0 1 1 1 1 0 SP.svg
The key and its associated value are then stored at that index. When a user wants to look up a value, the computer hashes the key again. This immediately indicates exactly where the corresponding value is located. In a well-designed table, the time it takes to find an item is independent of how many items are stored. This makes searching extremely fast compared to other methods.

However, most hash functions are imperfect. This leads to a situation called a hash collision. A collision occurs when the hash function generates the same index for two different keys. Because of this, every hash table must have a strategy to resolve these conflicts. One common method is called separate chaining.

Hash table 5 0 1 1 1 1 1 LL.svg
Hash table 5 0 1 1 1 1 1 LL.svg
In separate chaining, each slot in the bucket array holds a pointer to a linked list. If multiple items land in the same slot, they are chained together in that list. Another method is open addressing.
Hash table 5 0 1 1 1 1 0 LL.svg
Hash table 5 0 1 1 1 1 0 LL.svg
In open addressing, each slot holds only one item. If a collision occurs, the system follows a probing sequence to find the next available empty slot.

Efficiency in a hash table is often measured by the load factor. The load factor is the ratio of the number of stored elements to the total number of available slots. If the load factor is too high, the performance of the table begins to deteriorate. Software often manages this by resizing the table, a process known as rehashing. For separate chaining, the best performance usually happens when the load factor is between 1 and 3. For open addressing, the load factor can never exceed 1. In open addressing, performance drops sharply as the load factor approaches 1. Therefore, developers usually resize the table when the load factor reaches 0.6 to 0.75.

There are several ways to create a hash function. One common method is hashing by division. This involves taking the key and finding the remainder after dividing by the table size. Another method is hashing by multiplication. This uses a non-integer real-valued constant. The mathematician Donald Knuth suggested using the golden ratio for this method. When keys are strings rather than numbers, different rules apply. A simple string hash might involve shifting bits and using the XOR operation. Another approach is the polynomial rolling hash function. A perfect hash function is one where every key maps to a unique index. These can be created if all keys are known before the table is built.

The history of hashing involves many independent discoveries. In January 1953, Hans Peter Luhn wrote an internal IBM memorandum describing hashing with chaining. Shortly after, A. D. Linh proposed the first example of open addressing. At the same time, researchers at IBM like Gene Amdahl and Arthur Samuel implemented hashing for the IBM 701 assembler. Amdahl is also credited with open addressing using linear probing, an idea also held by Andrey Ershov. The term "open addressing" was later coined by W. Wesley Peterson. The word "hashing" itself was first published by Robert Morris. These early developments laid the groundwork for modern computing.

Using hash tables involves a specific space-time tradeoff. This means that developers must choose between using more memory or more processing time. If a computer had infinite memory, it could use the entire key as an index for instant access. If infinite time were available, the computer could ignore keys and use a linear search instead. In the real world, hash tables are often more efficient than search trees. They provide a balanced way to handle large amounts of data quickly. This makes them a cornerstone of efficient computer programming and data organization.

805 words
🖼️ Images & Media (4)
File:Hash table 3 1 1 0 1 0 0 SP.svg
Hash table 3 1 1 0 1 0 0 SP.svg
File:Hash table 5 0 1 1 1 1 1 LL.svg
Hash table 5 0 1 1 1 1 1 LL.svg
File:Hash table 5 0 1 1 1 1 0 LL.svg
Hash table 5 0 1 1 1 1 0 LL.svg
File:Hash table 5 0 1 1 1 1 0 SP.svg
Hash table 5 0 1 1 1 1 0 SP.svg
Up Next
💻
Associative array
Technology
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.