Horje
Time and Space Complexity of Linear Search Algorithm

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.




Reffered: https://www.geeksforgeeks.org


Algorithms

Related
Time and Space Complexity of Dijkstra’s Algorithm Time and Space Complexity of Dijkstra’s Algorithm
Dynamic Programming or DP Dynamic Programming or DP
Math Algorithms Math Algorithms
Time and Space Complexity of Breadth First Search (BFS) Time and Space Complexity of Breadth First Search (BFS)
Time and Space Complexity of Depth First Search (DFS) Time and Space Complexity of Depth First Search (DFS)

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12