Assuming I have a program like this:
def fn(array,num):
for i in range(0,len(array)):
if(i==num):print i
for i in range(o,len(array)):
for j in range(0,i):
if(i*j==num):print i,j
So the first loop runs in O(n) time . The second loop runs in O(n*n)time.
The overall time complexity would be O(n)+O(n^2) = O(n^2) time.(Is this right ??)
Also the space complexity would be O(n) as we have n blocks in memory to store n elements(Is this right ??) Is this the correct way to analyze the run time and space complexity?.I can analyze the time complexity of common sort algorithms and data strutures but Im having a bit of difficulty analyzing it just for a general program.Thanks!!