What is the time complexity of searching for a specific element in an unsorted…

2024

What is the time complexity of searching for a specific element in an unsorted array using a linear search ?

  1. A.

    O(1)

  2. B.

    O(log n)

  3. C.

    O(n)

  4. D.

    O(n^2)

Attempted by 70 students.

Show answer & explanation

Correct answer: C

In an unsorted array, there is no ordering information that lets us skip part of the array. A linear search checks elements one by one until the target is found or the array ends. In the worst and general case, it may inspect all n elements. Therefore, the time complexity is O(n).

Explore the full course: Tpsc Assistant Technical Officer