Coders Packet

Binary search tree class in Python

By Patnam Venkata Koushik

Implementing the functions of a binary tree class such as inserting, deleting, and printing the nodes using Python

A binary search tree is a node-based tree data structure that has the following properties:

1. the left child node has values lesser than the parent node

2. the right child node has values lesser than the parent node

3. the children nodes should have two children nodes to it in order to make it a complete binary tree

In this project, we have implemented the following functions that can be performed on a binary search tree:

1. search:

The input will be a number that has to be searched for, it will search for that particular value in the tree and return a boolean value

2. insert:

The input will be a number to be inserted, the defined function will put that element in the correct position in the tree

3. delete:

The input will be a number to be deleted, the defined function will delete the element from the tree and then it will rearrange the whole tree into a proper binary search tree

4. printTree:

This function is defined to print the binary tree in the following format -

N:L:x, R:y

where N is the data of any node present in the binary tree. x and y are the values of the left and right child of node N. Print the children only if it is not null.


Download Complete Code


No comments yet