Open In App

Time and Space Complexity of Linear Search Algorithm

Last Updated : 18 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The time complexity of the Linear Search algorithm is O(n), where n is the number of elements in the array. The space complexity is O(1) as it requires a constant amount of extra space regardless of the input size.

Linear Search Algorithm

Aspect Complexity
Time Complexity O(n)
Space Complexity O(1)

Let’s explore the detailed time and space complexity of the Linear Search Algorithm:

Time Complexity of Linear Search Algorithm:

Best Case Time Complexity of Linear Search Algorithm: O(1)

Best case is when the list or array’s first element matches the target element. The time complexity is O(1) because there is just one comparison made. So the best case complexity is O(1).

Average Case Time Complexity of Linear Search Algorithm: O(n)

The average case time complexity of the linear search algorithm is O(n), where n is the number of elements in the array being searched.

Worst Case Time Complexity of Linear Search Algorithm: O(n)

The worst-case will be when the target element is absent from the list or array or is located at the end of the list. O(n) time complexity results from the necessity to traverse the complete list and the n comparisons that are required.

Auxiliary Space Complexity of Linear Search Algorithm:

The auxiliary space complexity of the linear search algorithm is O(1), which means it uses a constant amount of additional space regardless of the size of the input array.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads