GATE DA 2025 · Linear Search & Binary Search

MSQ · 1 mark · Problem PROG-SRCH-0006

For which of the following inputs does binary search take time \(O(\log n)\) in the worst case?
  1. A
    An array of \(n\) integers in any order
  2. B
    A linked list of \(n\) integers in any order
  3. C
    An array of \(n\) integers in increasing order
  4. D
    A linked list of \(n\) integers in increasing order

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionBinary search achieves \(O(\log n)\) worst-case time only when it can jump directly to the middle element in \(O(1)\) time at every step — which requires both (a) random-access indexing (ruling out linked lists, where reaching the middle takes \(O(n)\) traversal time) and (b) sorted order (binary search's core correctness assumption).Only "an array of \(n\) integers in increasing order" satisfies both requirements simultaneously.Answer: An array of n integers in increasing orderClick Here for Detail SolutionGateOverflow discussion: https://gateoverflow.in/461005/gate-da-2025-question-17

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com