|Type||Unsorted associative array|
in big O notation
|Search||O(1 + n/k)||O(n)|
|Delete||O(1 + n/k)||O(n)|
A hash table is one type of tool for storing information. In computer science, these tools for keeping track of information, or data, are called data structures. A hash table is a data structure that uses a hash function to keep track of where data is put. Each piece of information to be stored has a name, which is called a key. For example, a key might be a person's name. Each name is matched up to one piece of data called a value, like the person's telephone number.
The idea behind a hash table is to figure out which box to put data by using only its name. This means, no matter how many boxes are filled up, you can always find information quickly if you have its name. The hash table uses a hash function to figure out which number to put data in from its name. The hash function reads a name and gives back a number.
A good Hash Table will always find information at the same speed, no matter how much data is put in. A lot of Hash Tables also let the user put key/value pairs (a name and its data) in and take them out at the same speed.
Because of this, Hash Tables can often find information faster than other tools, such as search trees or other table lookup structure. As a result, they are used in many kinds of computer software. They are used most for associative arrays, databases, caches, and sets.
References[change | change source]
- Thomas H. Cormen [et al.] (2009). Introduction to Algorithms (3rd ed.). MIT Press. pp. 253–280. ISBN 978-0-262-03384-8. Section 11: "Hash Tables".
- Donald Knuth (1998). 'The Art of Computer Programming'. 3: Sorting and Searching (2nd ed.). Addison-Wesley. pp. 513–558. ISBN 0-201-89685-0. Section 6.4: "Hashing".