If an Irish Rail list doubles in size, does searching it take twice the work?
Suppose an Irish Rail app searches a list of station names. The list doubles in size. Will the app need twice as many checks to find your station, or can it narrow down where to look?
Search these eight entries for twenty using linear search. You check each entry in turn. None matches, so you make eight checks. You can use that count to compare time efficiency. For auxiliary space, you'd measure the extra memory the algorithm uses.
Start with eight entries, then double to sixteen and again to thirty-two. If the target is first, you still make one comparison. If it's missing, the count doubles each time because you check every entry. The first pattern is constant growth. The second is linear growth.
A linear search checks all thirty entries because the target is missing. Now the list has sixty entries and the target is still missing. Pick the comparison count and the growth class that go together.
Let n be the list size. One check is constant. Halving down to one takes three steps from eight and four from sixteen: logarithmic growth. Checking every entry is linear. Multiply n by its logarithm for linearithmic growth. Square n for quadratic growth. The table gives tight upper bounds.
Double the list from eight to sixteen. On sorted data, binary search can halve the range three or four times, then check the last entry: four or five checks. Linear search can check all eight or sixteen. Selection sort scans each unsorted tail, giving twenty-eight comparisons, then one hundred and twenty.
Now double the sorted list from sixteen entries to thirty-two. Binary search needed up to five midpoint checks before the list grew. Pick how many midpoint checks it can need in the new worst case.
With distinct keys, compare each pivot once with every other key in its sublist. For random pivots, the average growth model rises from twenty-four to sixty-four. Those are model values. If every pivot is the smallest or largest remaining key, the exact worst-case count rises from twenty-eight to one hundred and twenty.
If you read big O of n as n seconds, you'd predict a sixty-second search for sixty entries. Big O bounds how the work grows. A linear search for a missing entry makes sixty checks here. How many seconds those checks take depends on the machine and the code.
If asked to compare the efficiency of the two searches, name the resource and case: time, measured by worst-case checks. Binary search grows logarithmically and needs sorted data. Linear search grows linearly and works on unsorted data. For one search on an unsorted list, linear search avoids sorting first.