Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>"Step" isn't a well-defined term in this context -- as <a href="https://stackoverflow.com/questions/17643272/running-time-does-print-count-as-a-step/17643472#comment25691621_17643272">pswaminathan points out</a>, usually what we care about isn't a precise numerical value but the mathematical behavior in a broader sense: as the problem size gets bigger (in this case, if you increase the size of the input <code>L</code>) does the execution time stay the same? Grow linearly? Quadratically? Exponentially?</p> <p>Explicitly counting steps can be a part of that analysis -- it can be a good way to get an intuitive handle on an algorithm. But we don't have a consistent way of determining what counts as a "step" and what doesn't. You could be looking at lines of code -- but in Python, for example, a list comprehension can express a long, complicated loop in a single line. Or you could be counting CPU instructions, but in a higher-level language full of abstractions that's hopelessly difficult. So you pick a heuristic -- in straightforward code like your example, "every execution of a single line of code is a step" is a decent rule. And in that case, you'd certainly count the print statements. If you wanted to get in a little deeper, you could look at the bytecode as <a href="https://stackoverflow.com/questions/17643272/running-time-does-print-count-as-a-step/17643472#comment25691768_17643272">tobias_k suggests</a>, to get a sense for what the instructions look like behind Python's syntax.</p> <p>But there's no single agreed-upon rule. You mention it's for homework; in that case, only your instructor knows what definition they want you to use. That said, the simple answer to your question is most likely "yes, the print statements count."</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload