Growth Rate

We have spent this chapter computing Big-Ohs. Linear search is , binary search is , selection sort is . The Big-Oh is a group name for a family of functions that share a growth rate.

Take . When we found that linear search is , we dropped the constant and the lower-order terms. So a step count of became . A step count of would also become . So would . So is not naming one function. It is naming a family of functions. Every member of the family, once you drop its constant and lower-order terms, grows in proportion to . What they share is how they respond to a bigger input: double the input and the work roughly doubles. When we call an algorithm , we are saying it scales that way.

Sharing a growth rate is not the same as doing the same amount of work. An algorithm that does steps does more work than one that does steps, which does more than one that does steps. At every input size, the algorithm is doing twice the work of the one. That difference in the constant is a real difference and it may matter depending on the task at hand. But the difference in the constant is tiny compared to the difference between families.

Compare , , and with an algorithm. At a million elements, we saw in an earlier section that a step count of costs about a second while a step count of costs about twelve days. Doubling or halving the linear one changes its cost to between half a second and two seconds. The quadratic one still costs about twelve days. Inside the family, the difference is a factor of two or four. Between the families, the difference keeps growing as grows, with no bound on it.

At small , the constant can decide which algorithm does less work. But eventually outgrows for any constant you pick, so there is always an input size past which the quadratic algorithm does more work. So the family decides which algorithm wins for large inputs. The constant only decides what input size we have to get to before that happens.