DSA Repository

Linear Search

In Linear Search, we iterate over all the elements of the array and check if it the current element is equal to the target element. If we find any element to be equal to the target element, then return the index of the current element. Otherwise, if no element is equal to the target element, then return -1 as the element is not found. Linear search is also known as sequential search.

Visualization

Slide 1 Slide 2 Slide 3

Time Complexity

CaseTime Complexity
Best CaseO(1)
Average CaseO(n)
Worst CaseO(n)

Where n is the number of elements in the array.

Space Complexity

CaseSpace Complexity
All CasesO(1)

Linear search uses a constant amount of extra space regardless of the input size.