Skip to main content

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

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

  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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Binary_Search_Trees-1.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for Binary_Search_Trees-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ac23729a596a31e5b597d3e87887abf2f8cc035274092c0e840f5f5143a6db4
MD5 12196fae633294cf842f5d5d2855b3ba
BLAKE2b-256 c68b1fbcc8f873ae16631d0e006866296ce7b4fba005ba85c3fe8bec3f10c96b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page