What are a key and a value in a hash table?
In a hash table, each element is stored as a "key -> value" pair.
Key is a unique identifier used to look up data. It passes through a hash function, which computes the index of the slot where the associated value is stored. Keys do not repeat: adding an element with the same key overwrites the old value.
Value is the actual data that needs to be stored or retrieved. The corresponding value can be found quickly by its key.
Example:
javascript
{ "name": "Maria", "age": 25, "city": "Kyiv" }"name","age","city"are the keys,"Maria",25,"Kyiv"are the values.
The hash function turns a key, for example "city", into an index, to instantly find "Kyiv".
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.