for A:
In the given code, we know that the time needed to run a single instruction is constant, (1 unit, say). Now, let's talk about the outer for loop, i. It runs for n times as given, also there is another loop inside the outer loop. So this inner loop runs n times for each value of outer loop.
So the total time taken by the code is: n2 + n + 1
When we talk about time complexity, we talk only about the highest degree term of n, which happens to be n2 in our case. neglecting all the constant time values as well, we get the time complexity as
O(n2).
for B:
In the given code, there is only one loop given, which run for n times.
So the complexity of the program is
O
for C:
let's have a look at the code
for j in range
: // runs for n times
test = test - 1 // runs for constant time
i = n while i > 0: // no matter the value of n, runs for only two times becuase i = n / 2.
k = 2 + 2 // constant time
i = i // 2
clearly , the time complexity of the above program is
O
Hope it helps...