void find (int n) {
if (n < 2) return;
else {
sum = 0;
for (i = 1; i <= 4; i++) find(n / 2);
for (i = 1; i <= n*n; i++)
sum = sum +1;
}
}
Suppose that the division operation takes a constant time, and suma global variable. What is time complexity find(n) ?
For me: since the first for loop runs 4 log nonce and the second for the run cycle n^2times. Thus, the total time complexity = O(4 log n + n^2) = O(n^2).
umang source
share