JAMIA 2025 — Computer PYQ
JAMIA | Computer | 2025What is the time complexity of binary search in a sorted array?
Choose the correct answer:
- A.
O(n)
- B.
O(log n)
(Correct Answer) - C.
(n log n)
- D.
O(1)
O(log n)
Explanation
Derivation
Let n be the number of elements in the array. In each step, the search space is reduced by half.
-
Step 1: n
-
Step 2: 2n
-
Step 3: 4n=22n
-
Step k: 2kn
The search ends when the remaining search space is reduced to 1:
2kn=1
n=2k
To solve for k (the number of steps), we take the logarithm on both sides:
log2(n)=log2(2k)
k=log2(n)
2. Time Complexities
| Case | Complexity | Description |
| Best Case | O(1) | Target element is the middle element. |
| Average Case | O(logn) | Target is found after several splits. |
| Worst Case | O(logn) | Target is at the ends or not in the array. |
3. Space Complexity
-
Iterative: O(1) (constant space).
-
Recursive: O(logn) (due to the recursion stack).
Final Answer:
The time complexity of binary search is O(logn).

