Why halving the range beats checking one by one, and when it does not.
About this comparison
Two boards hold the numbers 1 to 100 and hide the same number, 67. Both searches play the guessing game on one clock: one board guesses in order, the other guesses the middle and is told higher or lower.
Linear search guesses 1, then 2, then 3, and flips each wrong tile to a cross. It needs nothing from the numbers: in any order, it would still find 67 by looking at every tile until it meets it.
Binary search guesses the middle of the range still possible, floor((low + high) / 2). The reply rules out half of that range at once, and the board greys it out. This only works because the numbers are in order, so one reply says which side the hidden number is on.
Linear search removes one candidate per guess; binary search removes half of them. On n numbers that is up to n guesses, O(n), against about log2(n), O(log n). Both need O(1) extra memory.
Binary search guesses 50 (higher), 75 (lower), 62 (higher), 68 (lower), 65 (higher), 66 (higher), then 67. Seven guesses is its worst case for 100 numbers, so this is not a lucky draw. Linear search rules out 1 to 66 first and finds 67 on its 67th guess. Its board speeds up the later guesses so the run fits on screen, but every tile is flipped and counted.
Grow the game and the gap grows. With a million numbers, binary search needs at most 20 guesses; linear search could need all million.
Use linear search when the data is unsorted, small, or searched once. Sorting costs O(n log n), more than one pass, so sorting just to binary search once is a loss. It is also the only option on a linked list, where you cannot jump to the middle, and for a condition rather than an exact value, such as the first order over 100 dollars.
Use binary search when the data is sorted and searched often: a sorted list of IDs, a dictionary file, timestamps in a log. The same halving also searches over answers, such as the slowest speed that still finishes a job in time.