Which of the following search algorithms has the best worst-case time…
2024
Which of the following search algorithms has the best worst-case time complexity for searching a sorted array ?
- A.
Linear search
- B.
Binary search
- C.
Interpolation search
- D.
Hash table lookup
Attempted by 80 students.
Show answer & explanation
Correct answer: B
To determine the best worst-case time complexity for searching a sorted array, we must analyze how each algorithm performs as the input size grows. Binary search is the correct choice because it repeatedly divides the sorted array in half, eliminating 50% of the remaining elements with each step. This results in a worst-case time complexity of O(log n), which is significantly faster than linear search's O(n) for large datasets. While interpolation search can be faster on average (O(log log n)) for uniformly distributed data, its worst-case complexity degrades to O(n), making it less reliable than binary search for general sorted arrays. Hash table lookup offers average-case O(1) performance but is not applicable here as it requires a hash function and does not inherently rely on the array being sorted. Therefore, binary search provides the most efficient guaranteed performance for this specific problem.