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

Practice Questions

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

Questions & Step-by-Step Solutions

What is the time complexity of linear search in an unsorted array?
  • Step 1: Understand what linear search is. It means looking at each item in the array one by one.
  • Step 2: Know that in an unsorted array, you have to check every element to find the target value.
  • Step 3: If the array has 'n' elements, you might have to check all 'n' elements in the worst case.
  • Step 4: The time it takes to check each element adds up, leading to a total time of O(n).
  • Step 5: Conclude that the time complexity of linear search in an unsorted array 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