A Binary Heap is a binary tree that exhibits the heap property, either as a minimum heap (smallest value at the top of each binary tree) or a maximum heap (largest value at the top of each binary tree).
Write a program binary_heap.py
that defines a BinaryHeap
class as a Minimum Heap.
In general a Binary Heap needs the following methods:
BinaryHeap()
constructs a new empty binary heapinsert(value)
places a new value in the binary heap in an appropriate locationfind_min()
(for a MinHeap implementation) returns the minimum value in the heap, but doesn't remove itdel_min()
(for a MinHeap implementation) returns the minimum value in the heap and removes it from the heapis_empty()
returns True or False depending on the state of the heapsize()
returns the number of elements in the heapbuild_heap(value_list)
creates a new heap from the given list of valuesThe primary challenges with this assignment include:
Your program should include the BinaryHeap
class declaration as well as a main()
program that demonstrates the use of the class to create a minimum heap.