chap binary trees ( (bfigure two series of exchanges to build max-heap (athis heap is built by series of nine exchanges in the order ( - )( - )( - )( - )( - )( - )( - )( - )( - (bthis heap is built by series of four exchanges in the order ( - )( - )( - )( - figure final stage in the heap-building algorithm both subtrees of node are heaps all that remains is to push down to its proper level in the heap arraywith the first internal node the exchanges shown in figure (bresult from this process method buildheap implements the building algorithm what is the cost of buildheapclearly it is the sum of the costs for the calls to siftdown each siftdown operation can cost at most the number of levels it takes for the node being sifted to reach the bottom of the tree in any complete treeapproximately half of the nodes are leaves and so cannot be moved downward at all one quarter of the nodes are one level above the leavesand so their elements can move down at most one level at each step up the tree we get half the number of nodes as were at the previous leveland an additional height of one the maximum