Given 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
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
In general, the total time is for the elements
Total time complexity is therefore
Then
Subtracting we get
That is,
Which equals
That is,
So the time complexity is
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...
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...