Vidyalelo
Data Structure · Q317

Miscellaneous on Data Structures

Programming · Data Structure · question 317

Q317

What will be the recurrence relation of the following code? int xpowy(int x, int n) if (n==0) return 1; if (n==1) return x; if ((n % 2) == 0) return xpowy(x*x, n/2); else return xpowy(x*x, n/2) * x;

A.
T(n) = T(n/2) + n
B.
T(n) = T(n-1) + n
C.
T(n) = T(n-1) + O(1)
D.
T(n) = T(n/2) + O(1)
Answer

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board