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

Practice Questions

Q1
What is the time complexity of a linear search in an unsorted 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 unsorted array?
  • Step 1: Understand what a linear search is. It means looking at each item in the array one by one.
  • Step 2: Know that an unsorted array means the items are not in any specific order.
  • Step 3: Realize that in the worst case, you might have to check every single item in the array to find the one you are looking for.
  • Step 4: If there are 'n' items in the array, you will check 'n' items in the worst case.
  • Step 5: The time complexity is a way to express how the time taken grows with the number of items. Since you check each item once, the time complexity 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