Data Structures & AlgorithmsHardGATE CS · Product placement

A peak is an element larger than its neighbours (array ends count as −∞). Binary search runs on [16, 19, 40, 1, 18, 30, 54, 59, 45]: while lo < hi, mid = (lo + hi) // 2; if a[mid] < a[mid + 1] then lo = mid + 1 else hi = mid. Which index does it return?

  1. A. 2
  2. B. 4
  3. C. 8
  4. D. 7

Correct answer: D. 7

The search always moves towards a rising neighbour, so it ends on a local peak — index 7 (value 59). Peaks here: 2, 7.

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

Exams that ask this topic