I've been studying Big-O for an upcoming interview and I wanted something explained.
So one way I've been determining the run-time of algorithms is by counting the number of for-loops. For example, if an algorithm uses 1 for-loop I'd count that as O(n) and if it used two for-loops I'd say it was O(n^2). I find that this is generally an easy way to figure out time for simple algorithms. Although in a textbook I am reading they said this algorithm has an O(n^2) run-time.
a=5
b=6
c=10
for i in range(n):
for j in range(n):
x = i * i
y = j * j
z = i * j
for k in range(n):
w = a*k + 45
v = b*b
d = 33
How would this have an O(n^2) run-time? If ()=3+32+2+1=32+2+4 then are we just discarding the last loop (2n) because it does not add to 3n^2?
Thanks for reading!