Skip to main content

Linear Search

Pass the array of numbers/string along with the element which needs to be found.

Usage

src/sample/linearsearch.ts
import { linearSearch } from 'athro';

const arr = [2, 6, 3, 8];
const target = 6;

const result = linearSearch(arr, target)

Time Complexity

The time complexity of Linear Search is:

CaseTime ComplexityDescription
BestO(1)When the element is found at the 1st index
AverageO(n)When the elment is found at any index between 1 to n
WorstO(n)When the elelemnt is found at the last index