Skip to main content

A comprehensive Python library for tree data structures

Project description

ArborPy 🌳

CI PyPI version Python versions License: MIT

A comprehensive, typed, and well-tested Python library for tree data structures.

Installation

pip install 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

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

  • 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


Download files

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

Source Distribution

arborpy-0.1.0.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

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

arborpy-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file arborpy-0.1.0.tar.gz.

File metadata

  • Download URL: arborpy-0.1.0.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for arborpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f0a0ec86a3006c66fb3500a35b8a7a19178c0c2e4162b015d190e39f4165aba
MD5 88f1fb5b75474fef312b8221b64dc2cd
BLAKE2b-256 04546613741cb0019269f26969d169b04c0e2fa00deb542c86d025a64ce19a20

See more details on using hashes here.

Provenance

The following attestation bundles were made for arborpy-0.1.0.tar.gz:

Publisher: release.yml on prabhav-jalan/arborpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arborpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: arborpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for arborpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76978ceaddb82a80b8c9e538184809e04bf0dc613cd27b7752e957b034989ce5
MD5 3556fd8a07ed423c989718c9875d99da
BLAKE2b-256 56438d2cd5832a5a09d89ce18b082b5b18ced455b2c09241437533ff76215f5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for arborpy-0.1.0-py3-none-any.whl:

Publisher: release.yml on prabhav-jalan/arborpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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