This is a topic under computer-science and programming.
Heap in Python | Min Heap and Max Heap Implementation | FavTutor