This image reminds us of a _______________, which is one way we can implement ADT ___________________, whose functions include _____________ and _______________, with running times ____________________.
(min)Heap: buildHeap
(min)Heap: buildHeap — 3 alternatives
1. Sort the array
2.
def build_heap(self):for i inrange(2, self.size +1):self._heapify_up(i)
3.
def build_heap(self):for i inrange(self._parent(self.size), 0, -1):self._heapify_down(i)
(min)Heap: buildHeap
Thm: The running time of buildHeap on an array of size \(n\) is ________.
Instead of focusing specifically on running time, we observe that the time is proportional to the sum of the heights of all of the nodes, which we denote by \(S(h)\).
\(S(h) = \underline{\hspace{8em}}\)
\(S(0) = \underline{\hspace{4em}}\)
\(\text{Soln } S(h) = \underline{\hspace{8em}}\)
Proof of solution to the recurrence:
Given: \(S(h) = 2S(h-1) + h, S(0) = 0\)
Show: \(S(h) = 2^{(h+1)} - h - 2\)
But running times are reported in terms of \(n\), the number of nodes…