820 views

2 Answers

Best answer
0 votes
0 votes

It should be $O(n)$.

It can be written as:
 

while(n > 1){
    for(i = 1; i <= n; i++)
        temp = temp + 1;
    n = n / 2;
}

It should be $O(n)$. What I forgot was that the inner value of $n$ will also change.

So the first time, it will run $n$ times, then $n/2$ times and so on, thus making it $O(n).$
 

edited by
0 votes
0 votes
The answer should be O(n) as the inside value of n will change as well.

Related questions

0 votes
0 votes
0 answers
2
aditi19 asked Nov 6, 2018
336 views
f(n)=$2^n$g(n)=n!h(n)=$n^{logn}$ which one is true?A) f(n)=O(g(n)) and g(n)=O(h(n))B) f(n)=$\Omega(g(n)))$ and g(n)=O(h(n))C) g(n)=O(f(n)) and h(n)=O(f(n))D) h(n)=O(f(n))...