I want to write a function that tells me whether a given list is a min heap.
What I have written so far:
def is_min_heap(L):
return _is_min_heap(L, 0)
def _is_min_heap(L, i):
if
#base case
else:
return (L[i] < L[2*i+1] and _is_min_heap(L, 2*i+1)) and (L[i] < L[2*i+2] and _is_min_heap(L, 2*1+2))
I am not sure what the base case should be and is my recursive calls correct?
Also how can you control that the indexes are not eventually out of range?