PrincessCuCu9712 PrincessCuCu9712
  • 22-08-2019
  • Computers and Technology
contestada

)the efficiency for recursuvely calculating xn is

A.O(nlogn)

B. O(n)

C.O(logn)

D.O(n2)

Respuesta :

ExieFansler ExieFansler
  • 28-08-2019

Answer:

(B) O(n).

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.

Answer Link

Otras preguntas

What is a multiple of 10 32 24 2543654 2345452662 that are the same
What's the distance between the points (–9,2) and (–4,2)?
If x = (34•68)+245 what is 50% of x?
What is the solution to the system of equations? x+y = 2 x -y =4 (__ , ____)
What is the total cost of a purchase price of $2615 and a tax rate of 3%
(50 POINTS) Set the ball and the barrier about two feet apart on the table. Grasp both ends of the ruler. Push the ball using the center of the ruler so the b
(50 POINTS) Set the ball and the barrier about two feet apart on the table. Grasp both ends of the ruler. Push the ball using the center of the ruler so the b
someone deposits rs 40000 in a bank at the rate of 5%p.a. if he hsa to pay 5% of interest as income tax, how much will he get after 4 years
how to solve this? please answer #maths #form4
Algebra 2. Help! Which grows faster as x increases, x3 or 3x? Explain.