GATE / CS ARCHIVE

SIMILAR QUESTIONS / ALGORITHMS

Halve a sorted search interval to derive logarithmic work

2 questions solved the same way, newest first. Back to Algorithms

How these are solved

Worst-case binary search has one half-size recursive call with constant local work. 1994 requests the recurrence;2021 requests arithmetic-operation order.

1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 8, GATE 2021: What is the worst-case number of arithmetic operations in recursive binary search on a sorted n-element array? A Θ(√n); B Θ(log₂ n); C Θ(n²); D Θ(n).
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Each binary-search call performs constant arithmetic and reduces the remaining interval by roughly one half. The worst-case recurrence is T(n)=T(n/2)+Θ(1), so Θ(log n), B, under the standard unit-cost arithmetic model.

After j unsuccessful comparisons, at most about n/2j candidates remain. Reaching one candidate needs j≈log₂n. A call computes a midpoint and adjusts bounds using a constant number of arithmetic operations. This counts operations, not bit complexity of arbitrary-precision index arithmetic.

Original paper, page 59 · Answer key

Report issue

Binary search recurrence

Searching, Sorting & Selection

Question 1.7, GATE 1994: Which recurrence models worst-case binary search: T(n)=T(n/2)+k, 2T(n/2)+k, T(n/2)+log n, or T(n/2)+n?
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

A binary-search step compares the target with the middle key and discards one half. Only the surviving half is searched recursively, so there is one T(n/2) term, not two. Selecting and comparing the middle item takes constant time in an indexed array, represented by k. Repeated halving reaches a constant-size range after Θ(log n) steps. The recurrence presupposes constant-time midpoint access; a linked-list implementation has different access costs.

Original paper, page 1