Tricky Big-O complexity
- by timeNomad
public void foo (int n, int m)
{
int i = m;
while (i > 100)
i = i/3;
for (int k=i ; k>=0; k--)
{
for (int j=1; j<n; j*=2)
System.out.print(k + "\t" + j);
System.out.println();
}
}
I figured the complexity would be O(logn).
That is as a product of the inner loop, the outer loop -- will never be executed more than 100 times, so it can be omitted.
What I'm not sure about is the while clause, should it be incorporated into the Big-O complexity? For very large i values it could make an impact, or arithmetic operations, doesn't matter on what scale, count as basic operations and can be omitted?