Question
Discrete Mathematics

Time Complexity Analysis Due: May 9th, 2019 Math 4 6026 Heap Sort Another algorithm for sorting uses a specialized tree struc
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Given n=2^k-1=1+2+2^2+\cdots 2^{k-1} elements, first we place the 0-th element at the first position in the heap. This takes time O(1)

The next 2 elements (1,2) are placed at the left and right positions in the heap. Going down a height 1 takes time 1 and then adding this element takes another time 1. So total time is 2\times (1+1)

The next 4 elements (3,4,5,6) are placed the the left-left, left-right, right-left and right-right positions respectively. This takes time 4\times (2+1)

In general, the total time is 2^i\times (i+1) for the 2^i elements

Total time complexity is therefore S=\sum_{i=0}^{k-1}2^{i}(i+1)=2^0(1)+2^1(2)+2^2(3)+\cdots

Then k-1 2S2+1) 2)22 (2)23 (3) +..

Subtracting we get t-1

That is, t-1

Which equals S=2^k-2

That is, S = n-2-O(n)

So the time complexity is O(n)

Add a comment
Know the answer?
Add Answer to:
Discrete Mathematics Time Complexity Analysis Due: May 9th, 2019 Math 4 6026 Heap Sort Another algorithm for sorting uses a specialized tree structure called a "heap." Specifically, we wi...
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
  • Since we do not want to have to rewrite this code when the element type changes,...

    Since we do not want to have to rewrite this code when the element type changes, this classes uses a Comparator to assist in ordering the elements. You will need to complete the siftUpComparator() and siftDownComparator() methods in the LinkedHeap Class. siftUp §Added element may violate heap-order property §siftUp() restores order starting at added node §Processing will continue working up the tree until: úFinds properly ordered node & parent úReaches the root (reaches node without parent) siftDown §Restores heap’s order...

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