How does binary search compare to linear search in terms of efficiency for…

2024

How does binary search compare to linear search in terms of efficiency for finding an element in a sorted array ?

  1. A.

    Binary search is always slower

  2. B.

    Binary search is always faster

  3. C.

    They have the same efficiency

  4. D.

    Efficiency depends on the array size

Attempted by 56 students.

Show answer & explanation

Correct answer: B

In a sorted array, binary search can compare with the middle element and discard half of the remaining search space after each comparison. This gives binary search O(log n) time complexity. Linear search checks elements one by one and takes O(n) time in the general case. Therefore, binary search is more efficient than linear search for searching in a sorted array.

Explore the full course: Tpsc Assistant Technical Officer