Hashtable

From WikiMD's Wellness Encyclopedia

Hashtable is a data structure that implements an associative array abstract data type, a structure that can map keys to values. A hashtable uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.

Overview[edit | edit source]

Ideally, the hash function will assign each key to a unique bucket, but most hash table designs employ an imperfect hash function, which might cause hash collisions where the hash function generates the same index for more than one key. Such collisions are always accommodated in some way.

In a well-dimensioned hashtable, the average cost (number of instructions) for each lookup is independent of the number of elements stored in the table. Many hashtable designs also allow arbitrary insertions and deletions of key-value pairs, at constant average cost per operation.

Hash Function[edit | edit source]

In a hashtable, the hash function is used to compute an index into an array of buckets or slots, from which the correct value can be found. The ideal hash function will assign each key to a unique bucket, but this situation is rarely achievable in practice (unless the hash keys are fixed; i.e., new keys are not going to be inserted into the table after creation).

Collision Resolution[edit | edit source]

When the hash function causes a collision by mapping a new key to a cell of the hashtable that is already occupied by another key, the hashtable uses a method to determine a sequence of cells in which to search for a cell that is either empty or contains the key.

Applications[edit | edit source]

Hashtables are used in many different types of computer software, particularly for tasks such as database indexing, cache memory, and in certain algorithms such as Dijkstra's algorithm for finding the shortest path in a graph.

See Also[edit | edit source]

WikiMD
Navigation: Wellness - Encyclopedia - Health topics - Disease Index‏‎ - Drugs - World Directory - Gray's Anatomy - Keto diet - Recipes

Search WikiMD

Ad.Tired of being Overweight? Try W8MD's physician weight loss program.
Semaglutide (Ozempic / Wegovy and Tirzepatide (Mounjaro / Zepbound) available.
Advertise on WikiMD

WikiMD's Wellness Encyclopedia

Let Food Be Thy Medicine
Medicine Thy Food - Hippocrates

Medical Disclaimer: WikiMD is not a substitute for professional medical advice. The information on WikiMD is provided as an information resource only, may be incorrect, outdated or misleading, and is not to be used or relied on for any diagnostic or treatment purposes. Please consult your health care provider before making any healthcare decisions or for guidance about a specific medical condition. WikiMD expressly disclaims responsibility, and shall have no liability, for any damages, loss, injury, or liability whatsoever suffered as a result of your reliance on the information contained in this site. By visiting this site you agree to the foregoing terms and conditions, which may from time to time be changed or supplemented by WikiMD. If you do not agree to the foregoing terms and conditions, you should not enter or use this site. See full disclaimer.
Credits:Most images are courtesy of Wikimedia commons, and templates Wikipedia, licensed under CC BY SA or similar.

Contributors: Prab R. Tumpati, MD