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 ?
- A.
O(1)
- B.
O(log n)
- C.
O(n)
- 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).