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
| Case | Time Complexity | Description |
|---|---|---|
| Best | O(1) | Target found at the first index |
| Average | O(n) | Target found somewhere in the middle |
| Worst | O(n) | Target at the last index or not present |