heep
This library was created to simplify the concept of a heap by showing that it is simply an array that is treated as a complete binary tree with some additional properties such as maximum and minimum binary heap that help us solve some programming issues such as array sorting and priority queue this library is specially designed for beginners in data structures
Installation
You can install heep via pip:
pip install heep
Usage
For Min Binary Heap
from heep import minBinaryHeap
x = minBinaryHeap([5, 4, 6, 2, 8, 1, 3, 7, 9])
print(x)
Output
[1, 2, 3, 4, 8, 6, 5, 7, 9]
You Can Visualize The Heap With All Details (As A Complete Binary Tree)
from heep import minBinaryHeap
x = minBinaryHeap([5, 4, 6, 2, 8, 1, 3, 7, 9], detail=True)
print(x)
Output
╒════════════════╤══════════════╤═══════════════╕
│ Current node │ Left child │ Right child │
╞════════════════╪══════════════╪═══════════════╡
│ 1 │ 2 │ 3 │
├────────────────┼──────────────┼───────────────┤
│ 2 │ 4 │ 8 │
├────────────────┼──────────────┼───────────────┤
│ 3 │ 6 │ 5 │
├────────────────┼──────────────┼───────────────┤
│ 4 │ 7 │ 9 │
├────────────────┼──────────────┼───────────────┤
│ 8 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 6 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 5 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 7 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 9 │ None │ None │
╘════════════════╧══════════════╧═══════════════╛
You Can Add A New Value To The Heap
from heep import minBinaryHeap
x = minBinaryHeap([5, 4, 6, 2, 8, 1, 3, 7, 9], detail=True)
print(x)
x.add(0)
print(x)
Output
╒════════════════╤══════════════╤═══════════════╕
│ Current node │ Left child │ Right child │
╞════════════════╪══════════════╪═══════════════╡
│ 1 │ 2 │ 3 │
├────────────────┼──────────────┼───────────────┤
│ 2 │ 4 │ 8 │
├────────────────┼──────────────┼───────────────┤
│ 3 │ 6 │ 5 │
├────────────────┼──────────────┼───────────────┤
│ 4 │ 7 │ 9 │
├────────────────┼──────────────┼───────────────┤
│ 8 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 6 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 5 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 7 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 9 │ None │ None │
╘════════════════╧══════════════╧═══════════════╛
╒════════════════╤══════════════╤═══════════════╕
│ Current node │ Left child │ Right child │
╞════════════════╪══════════════╪═══════════════╡
│ 0 │ 1 │ 3 │
├────────────────┼──────────────┼───────────────┤
│ 1 │ 4 │ 2 │
├────────────────┼──────────────┼───────────────┤
│ 3 │ 6 │ 5 │
├────────────────┼──────────────┼───────────────┤
│ 4 │ 7 │ 9 │
├────────────────┼──────────────┼───────────────┤
│ 2 │ 8 │ None │
├────────────────┼──────────────┼───────────────┤
│ 6 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 5 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 7 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 9 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 8 │ None │ None │
╘════════════════╧══════════════╧═══════════════╛
You Can Get The Min Value In The Heap
from heep import minBinaryHeap
x = minBinaryHeap([5, 4, 6, 2, 8, 1, 3, 7, 9], detail=True)
print(x.get_min())
Output
1
You Can Extract The Min Value In The Heap (Get The Min Value And Delete It)
from heep import minBinaryHeap
x = minBinaryHeap([5, 4, 6, 2, 8, 1, 3, 7, 9], detail=True)
print(x)
print(f"Extracted Value: {x.extract_min()}")
print(x)
Output
╒════════════════╤══════════════╤═══════════════╕
│ Current node │ Left child │ Right child │
╞════════════════╪══════════════╪═══════════════╡
│ 1 │ 2 │ 3 │
├────────────────┼──────────────┼───────────────┤
│ 2 │ 4 │ 8 │
├────────────────┼──────────────┼───────────────┤
│ 3 │ 6 │ 5 │
├────────────────┼──────────────┼───────────────┤
│ 4 │ 7 │ 9 │
├────────────────┼──────────────┼───────────────┤
│ 8 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 6 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 5 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 7 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 9 │ None │ None │
╘════════════════╧══════════════╧═══════════════╛
Extracted Value: 1
╒════════════════╤══════════════╤═══════════════╕
│ Current node │ Left child │ Right child │
╞════════════════╪══════════════╪═══════════════╡
│ 2 │ 4 │ 3 │
├────────────────┼──────────────┼───────────────┤
│ 4 │ 7 │ 8 │
├────────────────┼──────────────┼───────────────┤
│ 3 │ 6 │ 5 │
├────────────────┼──────────────┼───────────────┤
│ 7 │ 9 │ None │
├────────────────┼──────────────┼───────────────┤
│ 8 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 6 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 5 │ None │ None │
├────────────────┼──────────────┼───────────────┤
│ 9 │ None │ None │
╘════════════════╧══════════════╧═══════════════╛
You Can Know How Many Values In The Heap
from heep import minBinaryHeap
x = minBinaryHeap([5, 4, 6, 2, 8, 1, 3, 7, 9], detail=True)
print(len(x))
Output
9
Note
The same methods in maxBinaryHeap with get_max and extract_max.
License
This project is licensed under the MIT LICENSE - see the LICENSE for more details.
Metadata
Release files for heep 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| heep-1.0.2.tar.gz | 5.3 kB | Without provenance | Details for heep-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| heep-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for heep-1.0.2-py3-none-any.whl |
Total release size: 10.4 kB
Release files / heep-1.0.2.tar.gz
| Download URL | heep-1.0.2.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26dfb0d3f2912b9063681b6945ca234f1712fbc6a0b14336eb3ae855fed7ed8b
|
|
BLAKE2b-256 checksum How to use checksums |
ecdb4ba480384c3be06a8ed25b7fcaac2b57e317477479b14127a5934e3fa0f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.2
|
Release files / heep-1.0.2-py3-none-any.whl
| Download URL | heep-1.0.2-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66358b721592399501231e55cfa52e51d29d5d7234d0f307e261e7b6ebbb50bd
|
|
BLAKE2b-256 checksum How to use checksums |
43861fc64f5e19facce67fe0c95b1367c1840be76d2a3db145422cb46f30d91f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.2
|
Security for heep 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.