Question
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size ?
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 , each recursive step computes the midpoint index, typically via or , which requires a constant number of arithmetic operations .
The search then recurses on one half of the array of size at most . The recurrence relation for the worst-case arithmetic operations is:
By the Master Theorem (Case 2 with ), the solution to this recurrence is:
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.