Skip to main content

Linear Search

Sequentially checks each element in the array until the target is found or the array ends.

Interactive Visualization

Loading visualization…

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

CaseTime ComplexityDescription
BestO(1)Target found at the first index
AverageO(n)Target found somewhere in the middle
WorstO(n)Target at the last index or not present