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

python
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,
?Assuming we have the following list of numbers:
>>> list_of_numbers = [48, 24, 37, 25, 38, 16, 50]
The heap would be created as follows:
heap=[]
for new_number in list_of_numbers:
heap = insert_heap(heap, new_number)
The output would be :
>>>heap
[50, 38, 48, 24, 25, 16, 37]
Create a three way heap (Modify the above functions) so that when creating the heap you would get the following:
>>> heap
[50, 48, 37, 25, 24, 16, 38]

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

1 Expert Approved Answer
Step: 1 Unlock

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

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!