Data Structures & AlgorithmsHardAmazon · Microsoft OA
A hash table with separate chaining and simple uniform hashing has n keys in m buckets (load factor α = n/m). What is the expected time of an unsuccessful search, and what keeps it O(1)?
- A. Θ(log n); balanced trees in each bucket
- B. Θ(α²); using a prime table size
- C. Θ(n); nothing can keep it constant
- D. Θ(1 + α); resizing keeps α bounded by a constant
Correct answer: D. Θ(1 + α); resizing keeps α bounded by a constant
An unsuccessful search hashes (O(1)) and scans one chain of expected length α. Doubling the table when α exceeds a threshold keeps α = O(1), and amortised resizing cost stays O(1) per insert.
More Coding Interview Problems questions
- An LRU cache must support get and put in O(1). Which design achieves this?
- Edge case: identity versus equality in Python. python a = [1, 2]; b = [1, 2]; c = a print(a == b, a is b, a is c, [] is []) What is printed?
- Edge case: chained comparisons and booleans as integers in Python. python print(1 < 2 > 1.5, (1 < 2) > 1.5, True + True, 3 > 2 == 2) What…
- Edge case: closures over a loop variable declared with var versus let in JavaScript. javascript const a = [], b = []; for (var i = 0; i <…
- Problem: Minimum number of swaps (any two positions) needed to sort an array of distinct values, by counting cycles of the permutation…
- Problem: Count subarrays whose sum lies in [lo, hi] using prefix sums and a sorted list (bisect). python from bisect import bisectleft…