Question

Q3. (a) Prove that n loga n is O(n2). Prove that n is not O(n2 log n). (5) (b) The multi Pop (i) method pops i items from the top of a stack. Analyse the amortized complexity of the multiPop (i) method (5)

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

to be able to pop i elements out of a stack we must first check if the stack actually has i or more elements and return false if it doesnt. If it does, we will count i elements and make top point to the i+1 th element from the top of the stack

bool multipop(i, node* top)

{

    node * temp = ⊤ int count = 1;

   while(count<i)

{

     if(temp->next == NULL)

            return false;

       else

       {

            temp = temp->next; count ++;

       }

}

top = &temp;

return true;

}

this process takes O(i) time.

Add a comment
Know the answer?
Add Answer to:
(a) Prove that n log^3 n is O(n^2). Prove that n^3 is not O(n^2 log n)....
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