Last updated:
0 purchases
BinarySearchTrees 1.0.2
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
MIT
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.