Contains Methods for operations in Binary Search Tree
Project description
Binary_Search_Trees
Installation
pip install Binary_Search_Trees
It is a module for Binary Search Tree Data Structures. It contains Methods to create,insert,delete,search,traverse and for many other useful Binary search Tree operations.
class Node:
def __init__(self, data=None):
self.left = None
self.right = None
self.data = data
from Binary_Search_Trees import BST as bst
Methods
=======================================
-
CreateBST()
By Default Creates a Root Node With data=None
Argument: data for Root Node -- Any value Can be passed,which will be assigned to root Node.
Returns : Address of Root Node of BST
root=bst.CreateBST()
-
GetLeftChild(Argument)
Argument: Node of object type
Returns : Address of left child of the Node
bst.GetLeftChild(root)
-
GetRightChild(Argument)
Argument: Node of object type
Returns : Address of Right child of the Node
bst.GetRightChild(root)
-
GetRootValue(Argument)
Argument: Node of object type
Returns : Data of the Node passed
bst.GetRootValue(root)
-
Insert(Argument1,Argument2,Argument3)
Argument1: Root Node
Argument2: Data to be Inserted --Can be : homogeneous list, int, float or string
Argument3: only in case of inserting dictionaries-- To insert dictionary values pass: 'values'
-- To insert dictionary keys pass: 'keys'Returns : Nothing
bst.Insert(root,4)# passing integer
bst.Insert(root,'d') #passing character
bst.Insert(root,57.733) # passing float value
bst.Insert(root,[4,1,2,7,5,9])# passing list
bst.Insert(root,{1:1,2:4,5:25,3:9},'values')# passing dictionary
bst.Insert(root,{1:1,2:4,5:25,3:9},'keys')
-
Inorder(Argument)
Argument: Root Node of BST which needs to be traversed
Returns : List of elements after inorder traversal
val=bst.Inorder(root)
print(val)
-
Preorder(Argument)
Argument: Root Node of BST which needs to be traversed
Returns : List of elements after preorder traversal
val=bst.Preorder(root)
print(val)
-
Postorder(Argument)
Argument: Root Node of BST which needs to be traversed
Returns : List of elements after postorder traversal
val=bst.Postorder(root)
print(val)
-
LevelOrder(Argument)
Argument: Root Node of BST which needs to be traversed
Returns : List of elements after levelorder traversal
val=bst.LevelOrder(root)
print(val)
-
Width(Argument)
Argument: Root Node of BST
Returns : Maximum width (int) of the a BST tree
val=bst.Width(root)
print(val)
-
Height(Argument)
Argument: Root Node of BST
Returns : Maximum height (int) of the a BST tree
val=bst.Height(root)
print(val)
-
Size(Argument)
Argument: Root Node of BST
Returns : Maximum width (int) of the a BST tree
val=bst.Size(root)
print(val)
-
MaxOfBST(Argument)
Argument: Root Node of BST
Returns : Maximum element present in a BST
val=bst.MaxOfBST(root)
print(val)
-
MinOfBST(Argument)
Argument: Root Node of BST
Returns : Maximum element present in a BST
val=bst.MinOfBST(root)
print(val)
-
Find(Argument1,Argument2)
Argument1: Root Node of BST
Argument2: Element to be searched
Return : If Found:
returns Address of Node which contains that element
else:
returns -1
val=bst.Find(root,4)
print(val)
-
isEmpty(Argument)
Argument: Root Node of BST
Returns : If Empty:
returns True
else:
returns False
val=bst.isEmpty(root)
print(val)
-
InorderPredecessor(Argument)
Argument: Any Node of BST
Returns : Address of its inorder predecessor
val=bst.InorderPredecessor(root)
print(val.data)
-
InorderSuccessor(Argument)
Argument: Any Node of BST
Returns : Address of its inorder successor
val=bst.InorderSuccessor(root)
print(val.data)
-
Delete(Argument1,Argument2)
Argument1: Root Node of BST Argument2: Any key element of BST to be deleted
Returns : Address of root after deleting the specified node
t=bst.Delete(root,4)
License
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 Distributions
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 Binary_Search_Trees-1.0.2-py3-none-any.whl.
File metadata
- Download URL: Binary_Search_Trees-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.4.2 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ac23729a596a31e5b597d3e87887abf2f8cc035274092c0e840f5f5143a6db4
|
|
| MD5 |
12196fae633294cf842f5d5d2855b3ba
|
|
| BLAKE2b-256 |
c68b1fbcc8f873ae16631d0e006866296ce7b4fba005ba85c3fe8bec3f10c96b
|