Unit 08

Searching Techniques

Finding a value is one of the most common operations in computing — and one decision, whether your data is sorted, completely changes how fast it can be.

3914 22314055 mid looking for 31: check mid (14) → too small → search right half only 223140

// each comparison eliminates half of what's left to check

What it is

Searching means locating a target value within a collection. The two foundational approaches are linear search, which checks elements one by one, and binary search, which repeatedly halves the search space — but binary search only works on sorted data.

The two core approaches

Where each struggles

Time complexity

AlgorithmBestWorstRequires sorted data?
Linear searchO(1)O(n)No
Binary searchO(1)O(log n)Yes

Quick check

← Sorting Techniques All topics →