What is the space complexity of the given code? [code] #include<stdio.h> int power(int x, int y) { if (y == 0) return 1; else

thanhthao

New member
What is the space complexity of the given code?
Code:
#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(1)
B. O(n)
C. O(log n)
D. O(n log n)
 

Tìm kiếm

Back
Top