This project implements a Binary Search Tree (BST) in Python with basic operations:
- Insert values
- Remove values (
remove_value) - Traversals (pre-order, in-order, post-order)
- Search for values
- Get minimum and maximum values
- Change a node's value
If you just want to try the tree without installing anything, copy tree.py into the same folder as your project and use:
from tree import Tree
tree = Tree()
tree.insert(5)
tree.insert(3)
tree.insert(7)
tree.print_in_order()If you want to use this as a Python package, you first need Git installed.
👉 Download Git if you don’t already have it.
Then install directly from GitHub using pip:
pip install git+https://github.com/Ahmedhm1/BST---Binary-Search-Tree-Python.gitNow you can import it anywhere:
from bst import Tree
tree = Tree()
tree.insert(10)
tree.insert(4)
tree.insert(12)
tree.print_in_order()from bst import Tree
# Create tree and insert values
test = Tree()
test.insert(5)
test.insert(8)
test.insert(6)
test.insert(9)
test.insert(3)
test.insert(4)
test.insert(2)
# Remove values
test.remove_value(5) # Removes root
test.remove_value(30) # Does nothing, value not found
# Print in-order traversal (left, root, right)
test.print_in_order()
# Print pre-order traversal (root, left, right)
test.print_pre_order()
# Print post-order traversal (left, right, root)
test.print_post_order()BST---Binary-Search-Tree-Data-Structure/
│
├── bst/ # Package source code
│ ├── __init__.py # Exports Tree
│ └── tree.py # Binary Search Tree implementation
│
├── test.py # Example test file
├── setup.py # Package setup script
├── pyproject.toml # (Optional) modern build file
└── README.md
➡️ View tree.py directly if you just want to read the implementation.