notesonly.in

One notebook for every subject — open it anywhere.

Log in

Searching algorithms: linear, binary search

Data Structures · Engineering

Study notes

Binary search 7 in [1,3,5,7,9,11]: mid index 2 is 5, too small, search right half [7,9,11]; mid is 9, too big, search [7]; found in 3 comparisons. Linear search would check up to 4 elements. In a million sorted items, binary needs at most 20 comparisons.

← Back to topics for Engineering