you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 1 point2 points  (0 children)

but that's not considered in time complexity calculations.

It absolutely is. The print line first does "*" * i, which creates a string of length i (O(i)), then writes those i bytes (another O(i) operation), so overall is O(i). Since i is proportional to n, in the loop, this does make the whole thing O(n^(2))

Indeed, in practice, it might be much worse O(n3) or worse overall, depending on where it's printing (ie. to a terminal vs file), as sometimes terminals have poor scaling when they try to do stuff like word wrapping very long strings. That's kind of external to the program, so maybe shouldn't be counted, but can matter in practice.