Question: please code do in python and done in 2 hours. Use the following code to represent a node of a Binary Tree: Class Node: def

please code do in python and done in 2 hours.

Use the following code to represent a node of a Binary Tree:

Class Node:

def __init__(self, value):

self.value = value

self.left = None

self.right = None

  1. Create a class BST and write the following functions:
    1. Write a function AddElement which takes a parameter value and insert a new node in the Binary Search Tree with the given value. (dont return or print anything)

class BST:

def __init__(self):

self.root = None

def AddElement(self, value):

// your code goes here

  1. Write a function FindElement which takes a parameter value and returns the node (not the value) with same value, otherwise returns None.

def FindElement(self, value):

// your code goes here

  1. Write a function Height that takes a parameter node and returns height of the node

def Height(self, node):

// your code goes here

part 2:

Use the following code to represent a node of a Binary Tree:

Class Node:

def __init__(self, value):

self.value = value

self.left = None

self.right = None

  1. Create a class BST and write the following functions:
    1. Write a function AddElement that adds an element in Binary search tree.

class BST:

def __init__(self):

self.root = None

def AddElement(self, value):

// your code goes here

  1. Write a function GetChildren that takes a parameter node and returns the left and right child (as a tuple) of the node. The function should return None if the node is the leaf node.

def GetChildren(self, node):

// your code goes here

Hint: To return a tuple: return (a,b)

  1. Write a function IsLeaf which takes a parameter node and returns True if the node is a leaf node, otherwise returns False.

def IsLeaf(self,node):

// your code goes here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!