recursive approach recursive approach can also be used to form heap from an array heapify(method is applied to the root it calls itself for the root' two childrenthen for each of these children' two childrenand so on eventually it works its way down to the bottom rowwhere it returns immediately whenever it finds node with no children once it has called itself for two child subtreesheapify(then applies trickledo (to the root of the subtree this ensures that the subtree is correct heap then heapify(returns and works on the subtree one level higher heapify(int indexif(index / - returnheapify(index* + )heapify(index* + )trickledown(index)/transform array into heap /if node has no children/return /turn right subtree into heap /turn left subtree into heap /apply trickle-down to this node this recursive approach is probably not quite as efficient as the simple loop using the same array our initial code fragment showed unordered data in an array this data was then inserted into heapand finally removed from the heap and written back to the array in sorted order in this procedure two size- arrays are requiredthe initial array and the array used by the heap in factthe same array can be used both for the heap and for the initial array this cuts in half the amount of memory needed for heapsortno memory beyond the initial array is necessary we've already seen how trickledown(can be applied to half the elements of an array to transform them into heap we transform the unordered array data into heap in placeonly one array is necessary for this thus the first step in heapsort requires only one array howeverthings are more complicated when we apply remove(repeatedly to the heap where are we going to put the items that are removedeach time an item is removed from the heapan element at the end of the heap array becomes emptythe heap shrinks by one we can put the recently removed item in this newly freed cell as more items are removedthe heap array becomes smaller and smallerwhile the array of ordered data becomes larger and larger thus with little planning it' possible for the ordered array and the heap array to share the same space this is shown in figure