Question: python ?Assuming we have the following list of numbers: >>> list_of_numbers = [48, 24, 37, 25, 38, 16, 50] The heap would be created as




The following are the functions for max heap using a Binary tree :(def get_parent(i # :if i % 2 == 1 j = i//2 #odd equation else return j j=i//2-1 :(def get_children(i left_child = i*2 + 1 right_child = i*2 + 2 return left child, right_child :(def insert_heap(heap, new_number (heap.append(new_number last_index = len(heap)-1 (heap = heapify(heap, last_index return heap :(def heapify(heap, index if index = parent_value heap[index], heap[parent_index] = parent value, my_value else: #finish return heap (heap = heapify(heap.parent_index return heap Assuming we have the following list of numbers Flist of num[48 34 37 35 38 16 50
Step by Step Solution
3.37 Rating (144 Votes )
There are 3 Steps involved in it
To create a threeway max heap you need to modify the functions provided for a binary max heap The main changes will be in the getparent and getchildre... View full answer
Get step-by-step solutions from verified subject matter experts
