Hey can anyone help me with my homework question to do with python and running time please? This is the question below:
In each code fragment given below, determine the number of steps and describe what the code accomplishes, i.e., what value of x has been output based on the value of the integer n. Assume the value of n has already been set. State your running times using the big-O notation. (Remember to throw away leading constants and lower-ordered terms!)
(a)
Python program:
x = 0
a = 6
b = 6
c = 1
for i in range(2*n):
x = x + c
c = c + b
b = b + a
print x
Running time:
Justification:
What does this code accomplish?
(b)
Python program:
x = 0
for i in range(1,n):
for j in range(1,n):
x = x + j/float(i*(i+1))
print x
Running time:
Justification:
What does this code accomplish?
(c)
Python program:
x = 1
while x < n:
x = x * 2
print x
Running time:
Justification:
What does this code accomplish?
I dont know how to figure out the running time or what it means by justification and what the code accomplishes. Can anyone help me out please?