If a station search feels instant today, what happens when the list doubles?
Your app searches a test list of Irish Rail station IDs. The search feels instant on your laptop. If the list doubles, will the search do twice as much work? It depends on where the ID is, or whether it’s there at all.
You go through the IDs in order, comparing each one with the target. Return true as soon as you find a match. Return false if you reach the end without one. In the call at the bottom, fourteen matches the first ID, so you never check the other three.
With four items, a first-item match takes one comparison. An absent target takes four. Double the list to eight and the first-item match still takes one, while an absent target takes eight. These counts show how the work grows without needing to time the search.
Now the list has thirty items. How many target comparisons do you make if the first item matches, and how many if the target is absent? Pick the pair in that order.
For a swap in bubble sort, you save one item, move the other and put the saved item back. In this quicksort partition, you use the first item as the pivot and leave it in the input. You put smaller items into one new list and the rest into the other.
With twelve items and no match, you make twelve comparisons. One swap saves one item, whatever the input size. One copying partition stores one entry per item except the pivot, so twelve minus one gives eleven. You’re counting occupied item slots for one step, rather than total memory for a sort.
Try the same counting with twenty items. The target is absent, and the partition copies every item except the pivot into new lists. Pick the pair that gives the target comparisons first and the extra item slots second.
One laptop timing tells you how long that run took. A faster run might have found the target on its first check, so you can’t conclude that it will always be faster. For a general claim, state the input size and the case, then explain how the counts change as the list grows.
If an exam asks you to compare and justify the comparison counts, start with a size. For one hundred items, a first-item match takes one check because you stop immediately. An absent target takes one hundred because you check every item. As the list grows, only the absent-target count grows.