time complexity.. again there was some mistake.



hi there.
this is my homework. I've been trying to get some result but things
haven't been gone well.
Those are the nested loop. And What I have to do is to get time
complexity T(n) of the nested loop assuming n=2^k.

---------------------------------------------------------------------------­---------------------

for(i = 0; i<=n; i++) {
j = n;
while( j>= 1) {
<body of the while loop> // Needs Θ(1)
j = j/2;
}


}


---------------------------------------------------------------------------­---------------------

What I got is T(n) = n{1 + (k+1)(Θ(1) + 1_} assuming j=n and j=j/2
and Θ(1) are unit operations.
So I did try to solve my result to get a neat expresion.
that's what I did
n=2^k => lg(n)=k
T(n) = n{1 + (k+1)(Θ(1) + 1)}
= n{1 + (lg(n) + 1)(Θ(1) + 1)}
= n{1 + lg(n)Θ(1) + lg(n) + Θ(1) + 1} // by distribution law
and
= n{1 + lg(n)Θ(1) + lg(n) + Θ(1)}
= n{1 + lg(n)Θ(1) + Θ(lg(n))}
= n{1 + Θ(lg(n)) + Θ(lg(n))}
= n{Θ(lg(n)) + Θ(lg(n))}
= n{Θ(lg(n))} = nΘ(lg(n)) = Θ(nlg(n))


is that right? I wanna know where it's right or not.
I guess it has something wrong. So I need your help.
I appreciate your generous help.
ps : don't say to me 'do you own homework'. I already tried many times.

.



Relevant Pages

  • Re: Program help
    ... > making the white space in the middle i am using a nested loop. ... This sounds like homework. ... write 22 stars on the first line but instead wrote 17? ...
    (comp.lang.cpp)
  • Re: time complexity.. again there was some mistake.
    ... Those are the nested loop. ... I appreciate your generous help. ... don't say to me 'do you own homework'. ...
    (sci.math)
  • time complexity
    ... Those are the nested loop. ... I wanna know where it's right or not. ... I appreciate your generous help. ... don't say to me 'do you own homework'. ...
    (comp.theory)
  • time complexity
    ... Those are the nested loop. ... I wanna know where it's right or not. ... I appreciate your generous help. ... don't say to me 'do you own homework'. ...
    (comp.programming)
  • Re: time complexity
    ... Those are the nested loop. ... I appreciate your generous help. ... don't say to me 'do you own homework'. ...
    (comp.theory)