What is the time complexity of this function Assume the init
What is the time complexity of this function? Assume the initial value of? is one. function f(i, n) {if (i
Solution
Answer B. (1)
Explanation: For the given function, assuming the initial value of i as 1.
There can be two cases:
a) i>=n
In this case, if condition is not satisfied, therefore it will not be executed. therefore the no of iteration is 1.
b) i<n
The number of iteration, for any value of n will always be 2.
Thus, in both the cases the number of iterations is constant.
Therefore, Time complexity of given function is (1).
