61.3k views
5 votes
)the efficiency for recursuvely calculating xn is

A.O(nlogn)

B. O(n)

C.O(logn)

D.O(n2)

User Optio
by
7.7k points

1 Answer

2 votes

Answer:

(B) O(n).

Step-by-step explanation:

When we recursively calculate xⁿ. We multiply x with itself n times.in doing so we have to do this operation n times .So the time complexity will come out to be O(n).

for ex:

int product(int a ,int n)

{

if(n==1)

return a;

return a*product(a,n-1);

}

This function will keep on doing these operation until it hit the base case it is doing the operation n times.

User Kausik Chat
by
8.4k points