time complexity

D

dondora

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.
 
J

Jack Klein

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.

Your question has nothing to do with the C++ language, even though you
may be trying to write code in C++. Your question is about order of
algorithms, and the group for that is
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top