|Share this post!| Hash tables are an efficient implementation
of a keyed array data structure, a structure sometimes known as
an associative array or map. If you're working in C++, you can
take advantage of the STL map container for keyed arrays
implemented using binary trees, but this article will give you
some of the theory behind how a hash table works. In a keyed
array, however, you would be able to associate each element with
a "key," which can be anything from a name to a product model
number. So, if you have a keyed array of employee records, you
could access the record of employee "John Brown" like this:
Keyed Arrays vs. Indexed ArraysOne of the biggest drawbacks to a
language like C is that there are no keyed arrays. In a normal C
array (also called an indexed array), the only way to access an
element would be through its index number. To find element 50 of
an array named "employees" you have to access it like this: