#include<stdio.h>
int power(int x, int y)
{
if (y == 0)
return 1;
else if (y%2 == 0)
return power(x, y/2)*power(x, y/2);
else
return x*power(x, y/2)*power(x, y/2);
}
int main()
{
int x = 2;
int y = 3;
printf("%d", power(x, y));
return 0;
}
a) O(n)
b) O(log n)
c) O(n log n)
d) O(n2)
What will be the time complexity of the following code which raises an integer x to the power y?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
What will be the time complexity of the following code which raises an integer x to the power y?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!