Runtime Analysis. Understanding the runtime of code involves deep thought. It amounts to asking: “How long does it take to do stuff?”, where stuff can be any conceivable computational process whatsoever. It simply cannot be done mechanically, at least for non-trivial problems. As an example, a pair of nested for loops does not automatically result in Theta(N2) runtime.
Cost Model. As an anchor for your thinking, recall the idea of a “cost model” from last lecture. Pick an operation and count them. You want the one whose count has the highest order of growth as a function of the input size.
Important Summations. This is not a math class so we’ll be a bit sloppy, but the two key sums that you should know are that:
- 1 + 2 + 3 + … + N is in Theta(N2)
- 1 + 2 + 4 + 8 + … + N is in Theta(N)