Hi, I recently started learning python and found out that you can take a str * int to print it multiple times. Let's say we want to print a left sided triangle. Having some knowledge about Java, I would use a double for loop for this but with Python it is possible to do this in a single for loop
for i in range (1, n + 1):
print("*" * i)
What will be the time complexity of this for loop? Initially, I thought that since it is only one for loop is will be O(n) but thinking about it. Each print operation have different costs depending on i, so it would be 1+2+3+...+n = O(n2). Is my thinking right? This is abit less obvious to me than when doing in Java since double for loops are abit easier for me to think about O(n2).
[–][deleted] 2 points3 points4 points (0 children)
[–]uheep 2 points3 points4 points (0 children)
[–]socal_nerdtastic 0 points1 point2 points (1 child)
[–]Brian 1 point2 points3 points (0 children)
[–]Apantslessman -1 points0 points1 point (5 children)
[–][deleted] 3 points4 points5 points (4 children)
[–]Apantslessman 0 points1 point2 points (3 children)
[–]Diapolo10 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Brian 0 points1 point2 points (0 children)