Time complexity for two pieces of code

Viewed 338

We've got 2 pieces of code:

int a = 3; 
while (a <= n) {
    a = a * a;
}

And:

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(); 
    } 
}

What is the time complexity of them? I think that the first one is: O(logn), because it's progressing to N with power of 2.
So maybe it's O(log2n) ?

And the second one I believe is: O(nlog2n), because it's progressing with jumps of 2, and also running on the outer loop.

Am I right?

2 Answers
Related