Skip to main contentSkip to solution

What is the worst-case scenario for a linear search in an array of 'n' elements?

Solution

✅ Correct Option: 1

Linear search checks elements one by one from the start. The worst case is when the target is the last element, because all nn elements must be compared, giving a time complexity of O(n)O(n).

The same nn comparisons are needed when the target is not in the array at all.


Option 2: this is the best case, since the search stops after 1 comparison, O(1)O(1).

Options 3 and 4: linear search does not use the order of elements, so whether the array is sorted or unsorted does not decide the worst case.

Keyboard Shortcuts

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