Hashing and finding closest points Flashcards
What is a dictionary data structure?
A dictionary is a data structure that supports MakeDictionary
What is the universe U in the context of dictionaries?
The universe ( U ) is the set of all possible elements that could be part of the subset ( S ) maintained by the dictionary.
Why is hashing used for dictionaries?
Hashing allows efficient dictionary operations by mapping a large universe ( U ) into a smaller hash table using a hash function.
What is a hash function?
A hash function maps elements from the universe ( U ) to positions in a smaller array (hash table) to store and retrieve elements efficiently.
What is a collision in a hash table?
A collision occurs when two different elements ( u ) and ( v ) are mapped to the same hash table position by the hash function.
How does chaining resolve hash collisions?
In chaining
What are the operations supported by hash tables?
Hash tables support Insert (add an element), Delete (remove an element), and Lookup (check membership and retrieve data).
What makes a hash function ‘good’?
A good hash function minimizes collisions by distributing elements uniformly across the hash table.
What is the probability of a collision in uniform random hashing?
With uniform random hashing, the probability that two random elements collide is exactly ( 1/n ), where ( n ) is the size of the hash table.
What is a universal class of hash functions?
A universal class of hash functions ensures that for any two distinct elements ( u ) and ( v ), the probability that ( h(u) = h(v) ) is at most ( 1/n ).
What is the advantage of universal hash functions?
Universal hash functions ensure efficient dictionary operations by reducing the likelihood of collisions, even in the worst case.
How is a universal hash function constructed?
A universal hash function can be constructed using linear functions modulo a prime ( p ), such as ( h(x) = (\sum a_i x_i) \mod p ).
Why is a prime ( p ) used in universal hashing?
Using a prime ( p ) ensures that modular arithmetic avoids divisibility issues, providing better collision guarantees.
What is the complexity of dictionary operations using hashing?
With universal hashing, the expected complexity of Insert, Delete, and Lookup operations is ( O(1) ).
How are hash tables used in the closest-pair algorithm?
Hash tables help divide the unit square into subsquares, allowing efficient Lookup of nearby points during the closest-pair algorithm.