What is the time complexity of linear search in an array?
Practice Questions
Q1
What is the time complexity of linear search in an array?
O(1)
O(n)
O(log n)
O(n^2)
Questions & Step-by-Step Solutions
What is the time complexity of linear search in an array?
Step 1: Understand what linear search is. It is a method to find a specific value in an array by checking each element one by one.
Step 2: Realize that in the worst-case scenario, you may have to check every single element in the array to find the target value or determine that it is not present.
Step 3: If the array has 'n' elements, checking each one means you will perform 'n' checks in the worst case.
Step 4: The time complexity is expressed using Big O notation, which describes the upper limit of the time taken as the size of the input grows.
Step 5: Since you may need to check 'n' elements, the time complexity of linear search is O(n).