Skip to main content

Binary tree implementation for Python

Project description

python-binary-tree

A simple implementation of a binary tree in Python.

Installation

pip install python-binary-tree

Usage

from binary_tree import BinaryTree
from binary_tree import BinaryTreeNode
# Create a binary tree and add nodes
bt = BinaryTree()
# Create nodes with values
root = BinaryTreeNode(0)
node1 = BinaryTreeNode(1)
node2 = BinaryTreeNode(2)
node3 = BinaryTreeNode(3)
node4 = BinaryTreeNode(4)
node5 = BinaryTreeNode(5)

# Add relationships between nodes
root.add_left(node1)
root.add_right(node2)

node1.add_right(node3)
node2.add_right(node4)
node1.add_left(node5)

# Insert nodes into the binary tree
bt.insert(root)
bt.insert(node1)
bt.insert(node2)

bt.draw()

Example Output

exampleplot.png

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

python_binary_tree-1.0.2.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

python_binary_tree-1.0.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file python_binary_tree-1.0.2.tar.gz.

File metadata

  • Download URL: python_binary_tree-1.0.2.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for python_binary_tree-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2f19b15f9b93187a40deacec67c0c6e92d1a8295dadc0321f08c1c2be8d547fa
MD5 b8ec905ec61f113e2460f8525de48c0b
BLAKE2b-256 790590f662ef192934d497cafcc57c9d890cbab1a31ddce58bf53558c90a5ee6

See more details on using hashes here.

File details

Details for the file python_binary_tree-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python_binary_tree-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6e04359b5556cefded838a41b66856f57378c314a520e45eab0764c50b252ac
MD5 44f308ac7219f50b7178404bdce6058c
BLAKE2b-256 aa3369d8c76f56fcfb491f02f351eb18e5b5ad71963e4cc3a1dc9424e740b706

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