python implementation of bottom-up heap construction implementing bottom-up heap construction is quite easygiven the existence of "down-heaputility function the "mergingof two equally sized heaps that are subtrees of common position pas described in the opening of this sectioncan be accomplished simply by down-heaping ' entry for examplethat is what happened to the key in going from figure ( to (gwith our array-based representation of heapif we initially store all items in arbitrary order within the arraywe can implement the bottom-up heap construction process with single loop that makes call to downheap from each position of the treeas long as those calls are ordered starting with the deepest level and ending with the root of the tree in factthat loop can start with the deepest nonleafsince there is no effect when down-heap is called at leaf position in code fragment we augment the original heappriorityqueue class from section to provide support for the bottom-up construction of an initial collection we introduce nonpublic utility methodheapifythat calls downheap on each nonleaf positionbeginning with the deepest and concluding with call at the root of the tree we have redesigned the constructor of the class to accept an optional parameter that can be any sequence of ( ,vtuples rather than initializing self data to an empty listwe use list comprehension syntax (see section to create an initial list of item composites based on the given contents we declare an empty sequence as the default parameter value so that the default syntax heappriorityqueuecontinues to result in an empty priority queue def init (selfcontents=))"""create new priority queue by defaultqueue will be empty if contents is givenit should be as an iterable sequence of ( ,vtuples specifying the initial contents ""empty by default self data self item( ,vfor , in contents if len(self data self heapifydef heapify(self)start self parent(len(self for in range(start- - )self downheap(jstart at parent of last leaf going to and including the root code fragment revision to the heappriorityqueue class of code fragments and to support linear-time construction given an initial sequence of entries