Operations On Binary Tree
Project description
easyBT
Make Binary trees easy for everyone it is used to serialize-deserialize binary trees and performs much more operations
- SerializeTree (tree nodes to list )
- DesializeTree (list to tree nodes )
- Height (Finds height of the tree) and Diameter (Finds diameter of the tree)
- InOrderTraversal,PostOrderTraversal,PreOrderTraversal
- LevelOrderTraversal
- MirrorTree
- LeafNodes,NumberOfLeafNodes
- VisualizeTree
Installation
Use the package manager pip to install easyBT.
pip install easyBT
Usage
from easyBT.binarytree import BinaryTree
# Create Object
bt=BinaryTree()
# add nodes in list
nums=[1,2,None,None,5,6]
# it will return root node of the tree
root=bt.DesializeTree(nums)
Examples
[1,2,3,4,5,6] [1,2,None,4,5,6]
1 1
/ \ /
2 3 2
/\ / / \
4 5 6 4 5
/
6
Documetation
To Read Documentation
print(bt.SerializeTree.__doc__)
DesializeTree
from easyBT.binarytree import BinaryTree
# Create Object
bt=BinaryTree()
# add nodes in list
nums=[100,500,20,10,30]
# it will return the root node of the tree
root=bt.DesializeTree(nums)
100
/ \
500 20
/ \
10 30
Visualize Tree
VisualizeTree(root)
#it will print
"""
['_', '_', '1', '_', '_']
['_', '2', '_', '3', '_']
['4', '_','5,6', '_', '_']
"""
BinarySearch Tree
- searchInBST (finds element in the bst)
- createBST (create bst)
- minValueNodeInBST (finds min value in the bst)
- maxValueNodeInBST (finds max value in the bst)
- deleteNode (delete node from the bst)
from easyBT.binarytree import BinarySearchTree
bst=BinarySearchTree()
Creation
data=[100,500,20,10,30]
root=None
root=bst.createBST(data=data)
100
/ \
20 500
/ \
10 30
Insertion
bst.insertInBST(root,40) or root=bst.insertInBST(root,40)
100 100
/ \ bst.insertInBST(40) / \
20 500 ---------> 20 500
/ \ / \
10 30 10 30
\
40
Deletion
bst.deleteNode(root,20)
50 50
/ \ deleteNode(20) / \
30 70 ---------> 30 70
/ \ / \ \ / \
20 40 60 80 40 60 80
bst.deleteNode(root,30)
50 50
/ \ deleteNode(30) / \
30 70 ---------> 40 70
\ / \ / \
40 60 80 60 80
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Contributors
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 easybt-0.0.9.tar.gz.
File metadata
- Download URL: easybt-0.0.9.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7519be2229bfd613cf49c2a9a759cb25229598f9d937ac89c00744cdf6fce840
|
|
| MD5 |
8018c57911f0bac27e00feaa845bda73
|
|
| BLAKE2b-256 |
360ac4b61d68fedbfe970a95724981eedb236074f9bf19107315a3b18cb5dfb3
|
File details
Details for the file easybt-0.0.9-py3-none-any.whl.
File metadata
- Download URL: easybt-0.0.9-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
137eec3ea4cb587ad47f351d803d9e45dc291a5b17cb72c0e597765b89156f6c
|
|
| MD5 |
e272f9c8b3090f77fb6011e016c8c9a6
|
|
| BLAKE2b-256 |
a32a87ad5a25c210f70fdfa65322622467239beeb6618f6616ceb5d45511f79c
|