Question 41
MediumA hash table with chaining has 100 slots and 250 keys. What is its load factor?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
A hash table with chaining has 100 slots and 250 keys. What is its load factor?
1
2.5
0.4
250
Sign up free to see the answer and a step-by-step explanation.
What is the expected time for a successful search with chaining at load factor α?
O(1 + α)
O(log α)
O(α²)
O(n)
Sign up free to see the answer and a step-by-step explanation.
Why can't open addressing use a load factor above 1?
It becomes chaining automatically
Each slot holds at most one key, so the table can't hold more keys than slots
Hash functions stop working
It can
Sign up free to see the answer and a step-by-step explanation.
Why is deletion awkward in open addressing?
It needs rehashing of the whole table every time
Emptying a slot can break the probe chain for keys inserted after it; a 'deleted' marker (tombstone) is used
Keys cannot be found at all
It is not allowed
Sign up free to see the answer and a step-by-step explanation.
What does a good hash function aim for?
Spreading keys uniformly over the slots, quickly
Producing sorted output
Being reversible
Mapping all keys to slot 0
Sign up free to see the answer and a step-by-step explanation.
What is the main drawback of linear probing compared with double hashing?
Primary clustering: runs of filled slots grow and slow down searches
It can't handle collisions
It uses more memory per key
It needs two hash functions
Sign up free to see the answer and a step-by-step explanation.
Which problem is a hash set the natural tool for?
Finding shortest paths
Sorting an array
Finding the k-th smallest element
Checking whether an array has any duplicate in O(n) expected time
Sign up free to see the answer and a step-by-step explanation.
Why might two different strings have the same hash code in Java?
Hash codes are 32-bit integers, so collisions are unavoidable for the infinite set of strings
Strings are mutable
Only for empty strings
Java has a bug
Sign up free to see the answer and a step-by-step explanation.
Since Java 8, what does HashMap do when one bucket gets too many entries (above 8)?
Doubles every bucket's size
Converts that bucket's list into a balanced tree
Throws an exception
Deletes the oldest entry
Sign up free to see the answer and a step-by-step explanation.
Which structure keeps keys in sorted order with O(log n) operations, unlike a hash map?
A balanced BST (TreeMap)
A queue
An unsorted array
HashSet
Sign up free to see the answer and a step-by-step explanation.