What is the time complexity of a linear search algorithm?

Practice Questions

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

Questions & Step-by-Step Solutions

What is the time complexity of a linear search algorithm?
  • Step 1: Understand what a linear search does. It looks at each item in a list one by one.
  • Step 2: Realize that if there are 'n' items in the list, the search may need to check all 'n' items.
  • Step 3: If the item is found early, it takes fewer checks, but in the worst case, it checks all 'n' items.
  • Step 4: The time it takes to complete the search grows linearly with the number of items, hence the term 'linear'.
  • Step 5: This is expressed in Big O notation as O(n), where 'n' is the number of items in the list.
No concepts available.
Soulshift Feedback ×

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

Not likely Very likely