PythiloLesson 17 of 32 · progress kept in this browser

Keep a min-heap in a plain list

A heap is a tree stored in a list: the children of index i sit at 2i+1 and 2i+2, and every parent is no larger than its children. The smallest item is always at index 0.

heap = [1, 4, 2, 9]
i = 3
print((i - 1) // 2)   # parent index 1
Your task

Write push(heap, value) and pop(heap) for a min-heap kept in a list, without the heapq module. pop removes and returns the smallest item.