Linear Search

Domain: Algorithms

🎯 Motivation

The simplest search: check each element one by one until you find the target or reach the end. O(n) but works on unsorted data.

πŸ“‹ Concrete Example

Search for 7 in [3, 1, 4, 1, 5, 7, 2]: check 3 (no), 1 (no), 4 (no), 1 (no), 5 (no), 7 (yes!). Found at index 5.

πŸ”— Analogy

Looking for a friend in a crowded MTR station by checking each person’s face one by one. Slow but works even if people are standing in random order.