Skip to main contentSkip to solution

What is the time complexity of linear search when the element is present at the first position of the list with 'n' elements?

Solution

✅ Correct Option: 1

Linear search compares the target with each element from the start. If the element is at the first position, it is found in a single comparison, no matter how large nn is. The time taken is constant, so the complexity is O(1)O(1).


Option 3: O(n)O(n) is the worst case (element at the last position or absent) and also the average case, not the best case.

Option 2: O(log⁡2n)O(\log_2 n) is the complexity of binary search, which needs a sorted list.

Best case of linear search is O(1)O(1), while worst and average cases are O(n)O(n).

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question