Hash tables
1.[2p] Why is a direct-address table unusable for ten thousand records keyed by a nine-digit identifier?
Why is a direct-address table unusable for ten thousand records keyed by a nine-digit identifier?
The answer is: It costs memory proportional to the universe of keys, a billion slots, rather than to the number stored
The answer is: It costs memory proportional to the universe of keys, a billion slots, rather than to the number stored
The answer is: It costs memory proportional to the universe of keys, a billion slots, rather than to the number stored
2.[2p] A sufficiently well designed hash function can avoid collisions entirely when the key universe is larger than the table.
A sufficiently well designed hash function can avoid collisions entirely when the key universe is larger than the table.
The answer is: False
3.[3p] About how many random keys go into a table of 1,000,000 slots before a collision is more likely than not? Use .
About how many random keys go into a table of 1,000,000 slots before a collision is more likely than not? Use .
4.[2p] A chained hash table has 500 slots and holds 900 keys. What is its load factor?
A chained hash table has 500 slots and holds 900 keys. What is its load factor?
5.[3p] Under linear probing at load factor 0.75, an unsuccessful search costs about probes. How many is that?
Under linear probing at load factor 0.75, an unsuccessful search costs about probes. How many is that?
6.[3p] Which of these are true of open addressing compared with separate chaining?
Which of these are true of open addressing compared with separate chaining?
Select all that apply
The answer is: Its cost rises far more steeply as the load factor approaches 1, Its load factor can never exceed 1, Deleting a record requires a tombstone rather than simply emptying the slot
7.[2p] Why must every key be reinserted when a hash table is resized?
Why must every key be reinserted when a hash table is resized?
The answer is: A key's slot is computed from the table size, so no old position is still correct
The answer is: A key's slot is computed from the table size, so no old position is still correct
The answer is: A key's slot is computed from the table size, so no old position is still correct
8.[3p] What does a hash-flooding attack exploit?
What does a hash-flooding attack exploit?
The answer is: Keys chosen to collide turn the table into a list, so insertions cost
The answer is: Keys chosen to collide turn the table into a list, so insertions cost
The answer is: Keys chosen to collide turn the table into a list, so insertions cost
9.[3p] Match each query to whether a hash table can answer it efficiently.
Match each query to whether a hash table can answer it efficiently.
Is this exact key present
What is the smallest key
List all keys in order
Insert a new key
no, every slot must be scanned
no, hashing destroys order
yes, expected constant time
yes, amortised constant time
Show the answer
Is this exact key present: yes, expected constant time What is the smallest key: no, every slot must be scanned List all keys in order: no, hashing destroys order Insert a new key: yes, amortised constant time