Question

Please explain why x = x + 1 is Theta(nlgn) code: i = n; while (i...

Please explain why x = x + 1 is Theta(nlgn)

code:

i = n;

while (i > 1)
{

i = floor(i/2);

x = x + 1;
}

why is is theta(nlgn)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Θ notation :

It is a best case complexity so it find exact time consuming .

From the question:

i = n; // It assign only once so its complexity is Θ (1)

while (i > 1) // Number of times the loop iterate is purely depend on the i value.
{

i = floor(i/2); // let n=13 then i values are 13,6,3,1(Since we use floor) and the value are exponentially decreased so its complexity is Θ (logn) so while loop complexity is Θ (logn)

x = x + 1; // Its complexity is logn.
}

Therefore the overall complexity is Θ(logn)

Note:

Small wrong in the question the complexity is Θ(logn).

Any doubts leave a comment

Add a comment
Know the answer?
Add Answer to:
Please explain why x = x + 1 is Theta(nlgn) code: i = n; while (i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT