How to calculate the complexity of a given code
问题 Function(int n) if(n<=2) return 1; for(i=n ; i>n/8 ; i-=n/2) for(j=n ; j>2 ; j=j/2) syso(); return Function(n/2); In order to calculate I have done the following : T(n) = T(n/2) + O(1) + 2logn T(n/2): the recursive call to the function. O(1) : the if statement. 2logn: the first "for" will run only 2 times * (the second "for") that will run logn times. ** I have assumed that the second for loop will divide the j by 2 meaning that I will have j/2^k times iterations = logn. With the same logic