Skip to main content

Python functions for working with Binary Heap

Project description

Binary Heap
###########

Python library which helps in forming Binary Heaps (Min, Max) using list data structure.
This library provides the below Heap specific functions.

1. heapify - Convert list of elements to Heap data structure
2. add_element - Add single/list of elements to Heap
3. extract_root - Extract root element from Heap and reform the Heap


Installation
========

install from pypi using pip::

$ pip install binary_heap

or easy_install::

$ easy_install binary_heap

or install from source using::

$ git clone https://github.com/rameshrvr/binary_heap.git
$ cd binary_heap
$ pip install .

Tutorial
========

1. Min Heap (Heap where the data in parent node is lesser than the data in child node)

.. code-block:: python

Rameshs-MBP-ead8:binary_heap rameshrv$ python3
Python 3.7.2 (default, Dec 27 2018, 07:35:06)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from binary_heap import MinHeap
>>> min_heap = MinHeap([4, 3, 6, 8, 11])
>>> min_heap.length()
5
>>> min_heap.elements()
[3, 4, 6, 8, 11]
>>> min_heap.add_element(1)
>>> min_heap.elements()
[1, 4, 3, 8, 11, 6]
>>> min_heap.add_element([1, 14, 7, 5])
>>> min_heap.elements()
[1, 4, 1, 7, 5, 6, 3, 14, 8, 11]
>>> min_heap.extract_root()
1
>>> min_heap.elements()
[1, 4, 3, 7, 5, 6, 11, 14, 8]
>>> min_heap.get_root_value()
1
>>>


2. Max Heap (Heap where the data in parent node is greater than the data in child node)

.. code-block:: python

Rameshs-MBP-ead8:binary_heap rameshrv$ python3
Python 3.7.2 (default, Dec 27 2018, 07:35:06)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from binary_heap import MinHeap
>>> max_heap = MaxHeap([4, 3, 6, 8, 11])
>>> max_heap.elements()
[11, 8, 6, 4, 3]
>>> max_heap.add_element(13)
>>> max_heap.elements()
[13, 8, 11, 4, 3, 6]
>>> max_heap.add_element([1, 14, 7, 5])
>>> max_heap.elements()
[14, 13, 11, 8, 5, 6, 1, 4, 7, 3]
>>> max_heap.extract_root()
14
>>> max_heap.elements()
[13, 8, 11, 7, 5, 6, 1, 4, 3]
>>> max_heap.get_root_value()
13
>>>

Development
===========

After checking out the repo, `cd` to the repository. Then, run `pip install .` to install the package locally. You can also run `python (or) python3` for an interactive prompt that will allow you to experiment.

To install this package onto your local machine, `cd` to the repository then run `pip install .`. To release a new version, update the version number in `setup.py`, and then run `python setup.py register`, which will create a git tag for the version, push git commits and tags, and push the package file to [PyPI](https://pypi.org).

Contributing
============

Bug reports and pull requests are welcome on GitHub at https://github.com/rameshrvr/binary_heap. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

License
========

The package is available as open source under the terms of the [GPL-3.0 License](https://opensource.org/licenses/GPL-3.0).

Code of Conduct
===============

Everyone interacting in the Binary Heap project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rameshrvr/binary_heap/blob/master/CODE_OF_CONDUCT.md).


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binary_heap-1.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

binary_heap-1.0.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file binary_heap-1.0.1.tar.gz.

File metadata

  • Download URL: binary_heap-1.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for binary_heap-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a7518a9cb642b336e027d9826acb934abc73c5916043745614c235a7eacdfc71
MD5 cf297459cd5ff4352f6da59998d54e15
BLAKE2b-256 586d6615f2830b0968a11dc5076e01a75e2463fe3592d7a29bf71c02bdfa55d9

See more details on using hashes here.

File details

Details for the file binary_heap-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: binary_heap-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for binary_heap-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dd892e8d5581434483cb65d9d944f12c01fb79de1410ac8e8a2131857708a7f
MD5 426881b7b1140430016b522515afe0e9
BLAKE2b-256 466119edb98cbc68d2b05dde1d6e48c2f7083b695df0c991c14b7b31cc005d1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page