Closed czgdp1807 closed 4 years ago
Passing an array of n inputs to the element is a good idea for implementing this.
Heap operations only consist of insert and extract, so I think we should implement only those methods for the public interface.
We can create a private method for _max_heapify
for max-heap and _min_heapify
for min-heap.
This suggests the following classes and their methods,
BinaryHeap
- Abstract class containing __new__
, insert
and extract
methods.MaxHeap
- Containing the _heapify
and inherits BinaryHeap
.MinHeap
- Containing the _heapify
and inherits BinaryHeap
.Moreover, __new__
of BinaryHeap
can look like,
def __new__(elements):
...
What do you say @23umesh ?
I am working on it, but as i am now working on C++ so it will take some time to create a final file and also your help. As for elements, maxsize,OneDimensinalArray(from pydatastructs) or a python list and type(min/max) would do the work. Or something else needed?
Please code the binary heap in Python 3.5.
I am working on the coding part using a python list. Should I do this part using OneDimensionalArray or DynamicOneDimensionalArray.Can you add the KWoC label to this issue?
Fixed by #46
Description of the problem
A new file is to be created under the
trees
directory named,heaps.py
and in that implementation of binary heap is to be added. Note that before making a PR first propose an API and class structure below. Once finalized, then move on to make a PR.Example of the problem
References/Other comments
https://en.m.wikipedia.org/wiki/Binary_heap