Chapter 5: Problem 7
It is tempting to compute the complexity of an algorithm by counting statements, as we did with the BubbleSort example, but only keeping track of the number of steps along the way up to \(O\left(^{*}\right)\). This turns out not to work with loops. For example, it is possible that each time through the loop, the number of statements executed is in \(\mathbf{O}(1)\). but that the number of statements executed by a loop of length \(n\) is not in \(\mathbf{O}(n)\). Find an example. (Hint: Each time through the loop, the number of statements executed may be in \(\mathrm{O}(1)\), but the constants \(c\) and \(N_{0}\) may change).
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.