When the data isn't sorted, when n is small, or when you only search once. Binary search requires sorted data as a precondition, so if the array is unsorted you'd have to sort it first (O(n log n)), only worth it if you'll search many times. For small n, a handful of elements, common in embedded, linear search is simpler, has no precondition, is cache-friendly (sequential access), and its small constant factor beats binary search's branching and the bookkeeping of lo/hi/mid; the asymptotic advantage of O(log n) doesn't kick in until n is reasonably large. And for a single lookup on unsorted data, scanning once is cheaper than sorting then searching. So linear search wins on small, unsorted, or search-once data; binary search wins on large, sorted, search-many data.
Data Structures & Algorithms · Interview question
When would you use linear search over binary search?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
Linear & Binary Search
O(n) linear scan works on anything; O(log n) binary search needs sorted data and gives deterministic worst-case timing, plus the overflow and off-by-one bugs that haunt it.