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?
O(1)
O(n)
O(log n)
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).