P
P
Pantene7422019-02-28 18:43:48
Algorithms
Pantene742, 2019-02-28 18:43:48

Hash table is an associative array of indices and addresses in memory?

I'm studying algorithms and I can't figure out how Hash tables work.
There is some data scattered in memory with certain addresses .... and an associative array where the indexes received by the hash function and the addresses assigned to them in memory are stored. So how then is the performance of Hash tables in books and lessons described as O (1) if we need to use binary search for example to get the address in memory while the indexes (keys) are sorted. log2 from array length...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2019-02-28
@Pantene742

The hash function determines an index in an array.
Accessing an element by index takes O(1)
You pass the key-value to the record "key1" -> "value1
" "value1"
We request the value for "key1" from the map - the hash from "key1" is calculated (got 12), subtracted element 12 from the array - got the value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question