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
- Create a class BST and write the following functions:
- 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
- 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
- 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
- Create a class BST and write the following functions:
- 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
- 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)
- 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
Get step-by-step solutions from verified subject matter experts
