Data Structures & AlgorithmsHardProduct company OA

Interpolation search (pos = lo + (key − a[lo]) · (hi − lo) / (a[hi] − a[lo]), integer division) looks for 32 in [1, 2, 4, 8, 16, 32, 64, 128] (0-based). How many probes does it make before finding 32?

  1. A. 4
  2. B. 1
  3. C. 3
  4. D. 6

Correct answer: A. 4

The values grow exponentially, so the linear estimate keeps landing too far left. Probe 1: 0 + 31·7/127 = 1 (value 2) → lo = 2. Probe 2: 2 + 28·5/124 = 3 (value 8) → lo = 4. Probe 3: 4 + 16·3/112 = 4 (value 16) → lo = 5. Probe 4: index 5 = 32. Four probes – more than binary search needs here (3). One probe happens only for evenly spaced data, where interpolation search shines.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic