Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary heap #38

Closed
czgdp1807 opened this issue Dec 2, 2019 · 5 comments
Closed

Add binary heap #38

czgdp1807 opened this issue Dec 2, 2019 · 5 comments
Labels

Comments

@czgdp1807
Copy link
Member

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

@czgdp1807
Copy link
Member Author

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,

  1. BinaryHeap - Abstract class containing __new__, insert and extract methods.
  2. MaxHeap - Containing the _heapify and inherits BinaryHeap.
  3. MinHeap - Containing the _heapify and inherits BinaryHeap.

Moreover, __new__ of BinaryHeap can look like,

def __new__(elements):
    ...

What do you say @23umesh ?

@23umesh
Copy link

23umesh commented Dec 8, 2019

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?

@czgdp1807
Copy link
Member Author

Please code the binary heap in Python 3.5.

@23umesh
Copy link

23umesh commented Dec 9, 2019

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?

@czgdp1807
Copy link
Member Author

Fixed by #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants