What is the time complexity of a linear search in an array?

Practice Questions

Q1
What is the time complexity of a linear search in an array?
  1. O(1)
  2. O(n)
  3. O(log n)
  4. O(n log n)

Questions & Step-by-Step Solutions

What is the time complexity of a linear search in an array?
  • Step 1: Understand what a linear search is. It means looking at each item in an array one by one.
  • Step 2: Realize that in the worst case, you might have to check every single item in the array.
  • Step 3: If there are 'n' items in the array, you will check 'n' items in the worst case.
  • Step 4: The time it takes to check each item is constant, so the total time is proportional to 'n'.
  • Step 5: Therefore, we say the time complexity of a linear search is O(n).
No concepts available.
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely