Say I have a function
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
System.out.println("Operation " + counter);
counter++;
}
}
}
Here complexity is n^3 and print operation runs n^3 times.
Suppose I have a program like fibanocci sequence:
public static int method6(int n) {
// complexity O(2^n)
if (n <= 1)
{
recursiveOperationCount += 1;
System.out.println("Operation1 " + recursiveOperationCount);
return n;
}
else {
recursiveOperationCount += 1;
System.out.println("Operation1 " + recursiveOperationCount);
return method6(n - 1) + method6(n - 2);
}
}
I know that the complexity is 2^n but the print operation happens 176 times for n = 10. Should the print have been printed 2^10 = 1024 times ?