Question 1Easy
What is the time complexity of linear search in the worst case?
- O(n log n)
- O(1)
- O(n)
- O(log n)
Answer: C. O(n)
Explanation
The key may be last or absent, so all n elements may be checked.
Step-by-step solution
- In the worst case the key is last or absent.
- Every one of the n elements is checked once.
Why the other options are wrong
- A. There is no sorting or splitting involved.
- B. O(1) is only the best case (key at index 0).
- D. O(log n) needs sorted data and binary search.
Tip: Linear: best O(1), worst O(n).