Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding items in an universal hash table?

Tags:

If items are organized randomly, how does the table know where to start looking?

In a non-random table items are organized according to some characteristic. (i.e. name). So if the table needs to look up some arbitrary information about "John", it can start looking in the 'J' bucket.

In a universal hash table though, items are arranged randomly. There's no defining characteristic. Therefore to find some arbitrary info about "John", wouldn't the table have to look through every bucket?

Isn't that a huge waste of time? It's like looking through every cabinet in your house to find a spoon.

like image 679
fdh Avatar asked May 02 '12 15:05

fdh


People also ask

How do I find an item in a hash table?

Whenever an element is to be searched, compute the hash code of the key passed and locate the element using that hash code as index in the array. Use linear probing to get the element ahead if the element is not found at the computed hash code.

How do you know if hash is universal?

A set H of hash functions is called a universal hash function family if the procedure “choose h ∈ H at random” is universal. (Here the key is identifying the set of functions with the uniform distribution over the set.)

What does it mean for a hash function to be universal?

In mathematics and computing, universal hashing (in a randomized algorithm or data structure) refers to selecting a hash function at random from a family of hash functions with a certain mathematical property (see definition below).

What does a hash table slot contain?

A hash table uses a hash function to compute an index, also called a hash code, into an array of buckets or slots, from which the desired value can be found. During lookup, the key is hashed and the resulting hash indicates where the corresponding value is stored.


1 Answers

While the previous answers are essentially correct, they don't directly address the random part of a universal hashing algorithm. Universal hashing algorithms do not use randomness when calculating a hash for a key. Random numbers are only used during the initialization of the hash table to choose a hash function from a family of hash functions. This prevents an adversary with access to the details of the hash function from devising a worst case set of keys.

In other words, during the lifetime of the hash table, the bucket for a given key is consistent. However, a different instance (such as next time the program runs) may place that same key in a different bucket.

like image 114
Chris Thornhill Avatar answered Oct 28 '22 20:10

Chris Thornhill