4 ms·
> Many of the examples are wrong. A python "print" statement is (for the built-in types at least) O(n), so printing the first item from a list must be at least
by ggchappell 12y ago
> Many of the examples are wrong. A python "print" statement is (for the built-in types at least) O(n), so printing the first item from a list must be at least O(n).
Yes & no. Big-O is about counting something and seeing how that amount changes when our independent variable (input size, maybe) gets large. We can count whatever we want.
It is correct to say that
print(x)
executes O(1) print statements. OTOH, it does not execute a constant number of single-character operations.
> I don't think the attitude of being allowed to be hand-wavey is a good one for this sort of thing. Big O notation has very precise semantics, and it is very easily misused.
That's a good point. Perhaps the best way to present big-O for "the masses" is (1) give people enough guidance to use it correctly, (2) make sure they know that this is not hand-wavey math, but rather one with precise definitions, but (3) not worry so much whether they know what those definitions are, or how to use them directly.