Question

What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size nn?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2021 answer key

Solution

Set up and solve the recurrence relation for the number of arithmetic operations performed by recursive binary search.

In recursive binary search on an array of size nn, each recursive step computes the midpoint index, typically via mid=low+(high−low)/2\text{mid} = \text{low} + (\text{high} - \text{low}) / 2 or (low+high)/2(\text{low} + \text{high}) / 2, which requires a constant number of arithmetic operations cc.

The search then recurses on one half of the array of size at most ⌊n/2⌋\lfloor n / 2 \rfloor. The recurrence relation for the worst-case arithmetic operations T(n)T(n) is:

T(n)=T(⌊n/2⌋)+c,T(1)=O(1)T(n) = T(\lfloor n / 2 \rfloor) + c, \quad T(1) = O(1)

By the Master Theorem (Case 2 with a=1,b=2,k=0a=1, b=2, k=0), the solution to this recurrence is:

T(n)=O(log⁡2n)T(n) = O(\log_2 n)
Final answer

B

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
Question
18 of 65, printed as CS Q.8
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.