What is the time complexity of binary search on a sorted array?
A
O(log n)
B
O(1)
C
O(n)
D
O(n^2)
Correct Answer: Option A — O(log n)
Explanation:
Binary search has a time complexity of O(log n) because it repeatedly divides the search interval in half, eliminating half of the remaining...
Binary search has a time complexity of O(log n) because it repeatedly divides the search interval in half, eliminating half of the remaining elements with each comparison. This makes it far more efficient than a linear search for large datasets.