Skip to content

himanshu-sagar/Binary_Search_Trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Binary_Search_Trees

Downloads Downloads PyPI version fury.io PyPI license

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
#or
import Binary_Search_Trees.BST as bst
#or
from Binary_Search_Trees.BST import *

Methods

=======================================

  1. 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()
  1. GetLeftChild(Argument)

    Argument: Node of object type
    Returns : Address of left child of the Node

bst.GetLeftChild(root)
  1. GetRightChild(Argument)

    Argument: Node of object type
    Returns : Address of Right child of the Node

bst.GetRightChild(root)
  1. GetRootValue(Argument)

    Argument: Node of object type
    Returns : Data of the Node passed

bst.GetRootValue(root)
  1. 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')
  1. 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)
  1. 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)
  1. 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)
  1. 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)
  1. Width(Argument)

    Argument: Root Node of BST
    Returns : Maximum width (int) of the a BST tree

val=bst.Width(root)
print(val)
  1. Height(Argument)

    Argument: Root Node of BST
    Returns : Maximum height (int) of the a BST tree

val=bst.Height(root)
print(val)
  1. Size(Argument)

    Argument: Root Node of BST
    Returns : Maximum width (int) of the a BST tree

val=bst.Size(root)
print(val)
  1. MaxOfBST(Argument)

    Argument: Root Node of BST
    Returns : Maximum element present in a BST

val=bst.MaxOfBST(root)
print(val)
  1. MinOfBST(Argument)

    Argument: Root Node of BST
    Returns : Maximum element present in a BST

val=bst.MinOfBST(root)
print(val)
  1. 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)
  1. isEmpty(Argument)

    Argument: Root Node of BST
    Returns : If Empty:
    returns True
    else:
    returns False

val=bst.isEmpty(root)
print(val)
  1. InorderPredecessor(Argument)

    Argument: Any Node of BST
    Returns : Address of its inorder predecessor

val=bst.InorderPredecessor(root)
print(val.data)
  1. InorderSuccessor(Argument)

    Argument: Any Node of BST
    Returns : Address of its inorder successor

val=bst.InorderSuccessor(root)
print(val.data)
  1. 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages