Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python programming only You have two tasks here. First read the task two and understand what's required to be done. Then with the help of

Python programming only

You have two tasks here. First read the task two and understand what's required to be done. Then with the help of task1 stated below complete the code required for the task 2.

image text in transcribed

You are also expected to test and demonstrate your implementation using a random binary search tree.

You should complete the code and verify that your code works using suitable test cases.

In addition, you are required to demonstrate your code by creating a binary search tree using some random numbers and then performing different operations on this binary search tree

The required partially completed codes are given below.

Partially completed binary tree

Follow the intructions to complete the binary tree as stated below.

image text in transcribed

class BTNode:

def __init__(self, val):

self.lChild = None

self.rChild = None

self.value = val

def AddLeftChild (self, NewValue):

if(self.lChild != None):

return -1

self.lChild = BTNode(NewValue)

return 1

def AddRightChild (self, NewValue):

if(self.rChild != None):

return -1

self.rChild = BTNode(NewValue)

return 1

def GetLeftChild (self):

return self.lChild

def GetRightChild (self):

return self.rChild

class BinaryTree:

def __init__(self):

self.root = None

def CreateBinaryTree (ElementList):

#Implement this method and return appropriate value.

return None

def ExpandBinaryTree (self, NewElementList):

#Implement this method and return appropriate value.

return None

def TraverseInOrder(self):

#Implement this method and return appropriate value.

return None

def TraversePreOrder(self):

#Implement this method and return appropriate value.

return None

def TraversePostOrder(self):

#Implement this method and return appropriate value.

return None

-------------------------------------------------------------------------------------------------------------------------------------

Instructions to complete the above binary tree

-------------------------------------------------------------------------------------------------------------------------------------

image text in transcribed

image text in transcribed

image text in transcribed

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Partially completed Binary Search Tree.

NOTE : BT_160000X.py is the completed code for the above binary tree code.

image text in transcribed

import BT_160000X.py

class BSTree(BinaryTree): def __init__(self): super(self.__class__, self).__init__()

def AddValue (self, NewValue): #Implement this method and return appropriate value. return None

def DeleteValue (self, DelValue): #Implement this method and return appropriate value. return None

def SearchValue (self, SearchValue): #Implement this method and return appropriate value. return None

def PrintTree (self): #Implement this method and return appropriate value. return None

Task 2: Implementing a Binary Search Tree In the second task of the lab, you are expected to extend your binary tree into a binary search tree. Your binary search tree should support following operations. def AddValue (NewValue) This function will add the value specified by NewValue to the binary search tree if the value is not present in the tree already (for simplicity we assume the values in the binary search tree will be unique). It returns 1 if addition is successful and returns -1 in failure. def DeleteValue (DelValue) This function will delete the value specified by Value from the tree if the value is present in the tree. It returns the deleted element if deletion is successful and returns None in failure. def SearchValue (SearchValue) This function will return a pointer to the node which contains value specified by Value in the tree if the value is present in the tree. If the value is not in the tree, it will return None. void PrintTree) This function will print the values in the tree in sorted order

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions