\"Peta-me.AS-Inurt ntnk! repl,.it HW3 - A5 - Insert into Min Heap repl talk my r
ID: 3745312 • Letter: #
Question
"Peta-me.AS-Inurt ntnk! repl,.it HW3 - A5 - Insert into Min Heap repl talk my repls loameteach Hgnadnr.. This is a preview. Take or import to see all content Due back ho clnssrocnm Irstructions fram your Iusert into Min Heap 1 Iron nath incort flccr in this assignment you will be working mutia min heap nstead of max heap. Tbe goal of this assignment is to implement the function insert_in_nin_heop() which will insert a new element into a min heap and then reheapify it et paretii): Retun the indox o the parent ot index 1. pturn fioot(i-1) ) I've given you a fionction called is min heap() whach does exactly what ut says it dces 7-def cet left childi: Expected behavrior heap 11,2,3,5,5,7,7 inscrt in min_heap (18, heap) hoop[1 len(heap) .. H is nin heap(heap) True Retum the Index of the left child of ndex .""" 11 def set right child(i) Return the index of the right child of index i." return i212 etu trua 11 tha array is a rax heap inap) left-al 1(heaplijheapLest-lef.child(1)l fon 1 1n rarge(s17e) right - all(naap[1] neaplest-right-child(1)] for 1 In ranga(s17 heap 11,2,3,5,5,7,7 insert in min heap(-8, heap) 1f eet-left-ch1ld(1)size) ) 1f eet_r'ent child(1) s!7*) len(heap) is nin heap(heap) rua 22-ef insert in nin heap(leent, hesp): heap [1,2,3,5, 5,7,7 inserl ir min hesp(4, hesp) +Your code here len(heap)8 is_nin_heap(heap)True Pythkm 3.6.1 (default, Dec 2015, 13:05:1) [GCC 4..2] on linuxExplanation / Answer
Function to check whether the given list is minheap or not ::
def is_min_heap(l):
for head in range(0, len(l)):
c1, c2 = head * 2 + 1, head * 2 + 2
if(l(0) > c2 || l(0) > c1)
return false
return true
heap list declaration
heap=[1,2,3,4,5]
check wheteher it is min heap or not by passing the list to the function named is_min_heap
here you can change the array elements and againg check whether the array is min heap or not by passing to that function .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.