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

DHeap added #118

Merged
merged 7 commits into from
Mar 11, 2020
Merged

DHeap added #118

merged 7 commits into from
Mar 11, 2020

Conversation

prshnt19
Copy link
Member

@prshnt19 prshnt19 commented Mar 2, 2020

References to other Issues or PRs or Relevant literature

Closes #102

Brief description of what is fixed or changed

Other comments

@codecov
Copy link

codecov bot commented Mar 2, 2020

Codecov Report

Merging #118 into master will increase coverage by 0.233%.
The diff coverage is 100%.

@@             Coverage Diff              @@
##           master      #118       +/-   ##
============================================
+ Coverage   97.94%   98.173%   +0.233%     
============================================
  Files          20        21        +1     
  Lines        1311      1588      +277     
============================================
+ Hits         1284      1559      +275     
- Misses         27        29        +2
Impacted Files Coverage Δ
pydatastructs/trees/__init__.py 100% <100%> (ø) ⬆️
pydatastructs/trees/heaps.py 98.314% <100%> (+0.738%) ⬆️
pydatastructs/trees/binary_trees.py 96.894% <0%> (-0.271%) ⬇️
pydatastructs/graphs/graph.py 100% <0%> (ø) ⬆️
pydatastructs/graphs/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/linear_data_structures/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/__init__.py 100% <0%> (ø) ⬆️
...datastructs/linear_data_structures/linked_lists.py 100% <0%> (ø) ⬆️
pydatastructs/graphs/algorithms.py 100% <0%> (ø)
... and 1 more

Impacted file tree graph

@prshnt19
Copy link
Member Author

prshnt19 commented Mar 2, 2020

The _build(self) in BinaryHeap doesn't seem to be doing anything. Its called once when the heap is to be built. At that time heap is empty so nothing actually happens.

@czgdp1807
Copy link
Member

Well by default, elements can be None so _build does nothing. However, if you pass some list in elements then _build will work.

@czgdp1807
Copy link
Member

Is it possible to remove the class BinaryHeap and add a constructor function with a same protoype as BinaryHeap.__new__?

def BinaryHeap(arguments accepted by BinaryHeap.__new__)

We can also add a special constructor for TernaryHeap.

@prshnt19
Copy link
Member Author

prshnt19 commented Mar 3, 2020

I think a better alternative will be to inherit DHeap. BinaryHeap and TernaryHeap will be a child class with d=2 and d=3 respectively.

class BinaryHeap(DHeap):
    def __new__(cls, elements=None, heap_property="min"):
         obj = DHeap.__new__(cls, elements=None, heap_property="min", d=2)
         return obj
class TernaryHeap(DHeap):
    def __new__(cls, elements=None, heap_property="min"):
         obj = DHeap.__new__(cls, elements=None, heap_property="min", d=3)
         return obj

@prshnt19
Copy link
Member Author

prshnt19 commented Mar 5, 2020

ping @czgdp1807

@czgdp1807
Copy link
Member

czgdp1807 commented Mar 8, 2020

Can we use DynamicOneDimensionalArray here instead of list?

@prshnt19
Copy link
Member Author

prshnt19 commented Mar 9, 2020

Can we use DynamicOneDimensionalArray here instead of list?

The DynamicOneDimensionalArray itself uses list. I think using DynamicOneDimensionalArray would be a good idea only if we use cyptes for DynamicOneDimensionalArray. This will give a performance boost. I can create a new issue for that.

@czgdp1807
Copy link
Member

Though DynamicOneDimensionalArray uses list but the deletion time for the same is amortized O(1) with a nice trade off with space complexity. What happens if we use it?

@prshnt19
Copy link
Member Author

prshnt19 commented Mar 10, 2020

Used DynamicOneDimensionalArray instead of List in DHeap.

DynamicOneDimensionalArray could be made faster using ctypes array. ctypes implementations are 10 to 100 times faster than python and takes less memory than python.

@czgdp1807
Copy link
Member

DynamicOneDimensionalArray could be made faster using ctypes array. ctypes implementations are 10 to 100 times faster than python and takes less memory than python.

Can you please make an experimental PR for the same?

@czgdp1807 czgdp1807 merged commit e811970 into codezonediitj:master Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add m-ary heap
2 participants