Question 71
HardHow does a consistent-hashing ring decide which server stores a key?
- 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
How does a consistent-hashing ring decide which server stores a key?
The key is placed on the ring and stored on the first server clockwise from it
The largest server
At random
Key mod number of servers
Sign up free to see the answer and a step-by-step explanation.
What is the false-positive rate of a Bloom filter mainly controlled by?
The order of insertion
The CPU speed
The number of bits per element and the number of hash functions
The key length
Sign up free to see the answer and a step-by-step explanation.
Two keys have the same hash code but are different. What must a hash map do?
Rehash the whole table
Store both and use equals() (or ==) to tell them apart on lookup
Overwrite one
Throw an error
Sign up free to see the answer and a step-by-step explanation.
What is the expected time to find the first non-repeating character in a string using a hash map?
O(1)
O(n)
O(n²)
O(n log n)
Sign up free to see the answer and a step-by-step explanation.
A minimal perfect hash function is built for a fixed set of n keys. What does it map them to?
Exactly the slots 0 to n − 1, one key per slot
Slots 0 to 2n
Random slots with some collisions
A single slot
Sign up free to see the answer and a step-by-step explanation.
When Java's HashMap resizes from capacity 16 to 32, where can an entry from bucket 5 end up?
Any bucket
Bucket 10
Bucket 5 or bucket 21
Bucket 0
Sign up free to see the answer and a step-by-step explanation.
Which problem is solved in O(n) by storing each element's index in a hash map as you scan?
Matrix multiplication
Finding the median
Two-sum: finding indices of two numbers that add to a target
Sorting
Sign up free to see the answer and a step-by-step explanation.
What is rolling-hash collision probability with a modulus p (prime) roughly proportional to, for two different strings of length m?
1
m / p
1 / m
p / m
Sign up free to see the answer and a step-by-step explanation.
Which data structure gives O(1) average insert, delete and getRandom?
A balanced BST
A heap
A linked list
A hash map from value to index plus an array, swapping the deleted element with the last
Sign up free to see the answer and a step-by-step explanation.
Why is a hash set a poor choice when you need the elements in sorted order?
Hash sets are always sorted
Hash sets can't store numbers
Hash sets keep insertion order only
Hashing scatters elements, so getting them in order needs an O(n log n) sort
Sign up free to see the answer and a step-by-step explanation.