Nepedia
Back to Discover
Fluent Reader
💻

Associative array

technology Maturity 11-13 Next article →

Computers use many ways to organize information. One very important tool is the associative array. You might also hear it called a map, a dictionary, or a key-value store.

Hash table average insertion time
Hash table average insertion time

This tool works by linking a unique key to a specific value. Think of a library where book titles are the keys. The person who borrowed the book is the value. Each key can only appear once in the collection. This makes it a very organized way to manage data.

There are three main actions you can perform with an associative array. The first is called an insert or a put operation. This adds a new key and value pair to the group. If the key already exists, the old value is simply overwritten. The second action is to remove or delete a pair. You provide the key, and the computer unmaps it from its value. The third action is a lookup, also called a find or a get. You give the computer a key, and it returns the value bound to it.

Hash table average insertion time
Hash table average insertion time

Computer scientists have spent a long time solving the dictionary problem. This is the hard job of making these arrays work very quickly. Many people have studied how to build the best structures for this. For example, researchers M. Dietzfelbinger and others wrote about perfect hashing in 1994. They looked at how to make these systems work well.

Hash table average insertion time
Hash table average insertion time

Different methods exist depending on how many items you need to store. Some methods are simple but slow, while others are complex and fast.

There are two major ways to build these arrays. The most common way is using a hash table. A hash table uses a math rule called a hash function. This rule puts each key into a separate bucket in an array. This makes finding items very fast, usually in constant time.

Hash table average insertion time
Hash table average insertion time

Another way is to use a self-balancing binary search tree. These trees, like red-black trees, keep all the keys in a specific order. This allows you to find a range of values easily. While hash tables are often faster on average, trees are better in a worst-case scenario.

Associative arrays are used in almost every programming language today. Some languages include them as a basic part of the system. Others provide them through software libraries.

Hash table average insertion time
Hash table average insertion time

The first language to have built-in support was SNOBOL4 in 1969. It called this feature a "table." You can think of these arrays like a digital filing cabinet. Just as you use a label to find a folder, a computer uses a key to find data. This simple idea helps computers handle huge amounts of information every second.

443 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (1)
File:Hash table average insertion time.png
Hash table average insertion time.png
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.