A comprehensive Python library for tree data structures
Project description
ArborPy 🌳
A comprehensive, typed, and well-tested Python library for tree data structures.
Installation
pip install arborpy
Or with uv:
uv add arborpy
Quick Start
from arborpy import BinarySearchTree
bst = BinarySearchTree()
for val in [5, 3, 7, 1, 4]:
bst.insert(val)
print(bst.inorder()) # [1, 3, 4, 5, 7]
print(bst.search(4)) # True
print(5 in bst) # True
print(len(bst)) # 5
print(bst) # Pretty-printed tree
Features
Binary Search Tree
from arborpy import BinarySearchTree
bst = BinarySearchTree()
# Insert values
for val in [5, 3, 7, 1, 4, 6, 8]:
bst.insert(val)
# Search
bst.search(4) # True
bst.search(99) # False
# Delete
bst.delete(3)
# Min and max
bst.find_min() # 1
bst.find_max() # 8
# Tree properties
bst.height() # 2
len(bst) # 7
AVL Tree
from arborpy import AVLTree
avl = AVLTree()
for val in [10, 20, 30, 25, 28]:
avl.insert(val)
print(avl) # Pretty-printed balanced tree
print(avl.inorder()) # [10, 20, 25, 28, 30]
print(avl.height()) # 2 — stays balanced!
AVL Tree
from arborpy import AVLTree
avl = AVLTree()
for val in [10, 20, 30, 25, 28]:
avl.insert(val)
print(avl) # Pretty-printed balanced tree
print(avl.inorder()) # [10, 20, 25, 28, 30]
print(avl.height()) # 2 — stays balanced!
Traversals
from arborpy import BinarySearchTree
bst = BinarySearchTree()
for val in [5, 3, 7, 1, 4, 6, 8]:
bst.insert(val)
bst.inorder() # [1, 3, 4, 5, 6, 7, 8]
bst.preorder() # [5, 3, 1, 4, 7, 6, 8]
bst.postorder() # [1, 4, 3, 6, 8, 7, 5]
bst.level_order() # [[5], [3, 7], [1, 4, 6, 8]]
Serialization
from arborpy import BinarySearchTree, to_json, from_json, to_dict, from_dict
bst = BinarySearchTree()
for val in [5, 3, 7]:
bst.insert(val)
# To/from dictionary
d = to_dict(bst.root)
node = from_dict(d)
# To/from JSON
json_str = to_json(bst.root)
node = from_json(json_str)
Standalone Traversal Functions
from arborpy import Node, inorder, preorder, postorder, level_order
# Build a tree manually
root = Node(1, Node(2, Node(4), Node(5)), Node(3))
inorder(root) # [4, 2, 5, 1, 3]
preorder(root) # [1, 2, 4, 5, 3]
postorder(root) # [4, 5, 2, 3, 1]
level_order(root) # [[1], [2, 3], [4, 5]]
Roadmap
<<<<<<< HEAD
- Binary Search Tree
- Traversals (inorder, preorder, postorder, level-order)
- Serialization (dict, JSON)
- ASCII visualization
- AVL Tree (self-balancing)
- Min/Max Heap
- Red-Black Tree
- Trie (prefix tree)
- Segment Tree
- Fenwick Tree (Binary Indexed Tree)
- N-ary Tree
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arborpy-0.2.0.tar.gz.
File metadata
- Download URL: arborpy-0.2.0.tar.gz
- Upload date:
- Size: 79.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df140d341d3afb488854fd11b775d979afffa2f563e47176f0b5b78acf801e96
|
|
| MD5 |
c2e9ecfbfe779661102c29935b4fc4a0
|
|
| BLAKE2b-256 |
cfcd234fdec1af02a1a75d1932b51c84298e98e90c221de7638bdf206329cdb0
|
Provenance
The following attestation bundles were made for arborpy-0.2.0.tar.gz:
Publisher:
release.yml on prabhav-jalan/arborpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arborpy-0.2.0.tar.gz -
Subject digest:
df140d341d3afb488854fd11b775d979afffa2f563e47176f0b5b78acf801e96 - Sigstore transparency entry: 1263692431
- Sigstore integration time:
-
Permalink:
prabhav-jalan/arborpy@0f07bf46b3f1e4cb6f18bc24e8489a3f2b27b729 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/prabhav-jalan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0f07bf46b3f1e4cb6f18bc24e8489a3f2b27b729 -
Trigger Event:
push
-
Statement type:
File details
Details for the file arborpy-0.2.0-py3-none-any.whl.
File metadata
- Download URL: arborpy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86c375ca58772a2f5235f27d2799890f4ed26e29c7b9cf9716790ae34f1c0265
|
|
| MD5 |
851d6af5d1b70d2bfd6abb1a2445c338
|
|
| BLAKE2b-256 |
3382f6d2ab403f399f8df08db1c477449b7e1744281f16e5072e49252de467df
|
Provenance
The following attestation bundles were made for arborpy-0.2.0-py3-none-any.whl:
Publisher:
release.yml on prabhav-jalan/arborpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
arborpy-0.2.0-py3-none-any.whl -
Subject digest:
86c375ca58772a2f5235f27d2799890f4ed26e29c7b9cf9716790ae34f1c0265 - Sigstore transparency entry: 1263692529
- Sigstore integration time:
-
Permalink:
prabhav-jalan/arborpy@0f07bf46b3f1e4cb6f18bc24e8489a3f2b27b729 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/prabhav-jalan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0f07bf46b3f1e4cb6f18bc24e8489a3f2b27b729 -
Trigger Event:
push
-
Statement type: