Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in Python!! Implement the following operations for a Binary Search Tree class. Use the Class TreeNode that is provided. You may implement

I need help in Python!!

Implement the following operations for a Binary Search Tree class. Use the Class TreeNode that is provided. You may implement helper methods that make your code easier to write, read, and understand.You may use iterative or recursive functions in your implementation. You will likely want to add setters and getters for the tree node fields other than the key field. Changing the key of a node is equivalent to removing and inserting it and that is the safer way to do the implementation rather than trying to move the node to reflect the change in the key. To implement BST use two classes, because you must be able to create and work with a BST that is empty. The class BinarySearchTree has a reference to the class TreeNode that is the root of the BST. The class TreeNode provides many helper functions that make implementation in class BinarySearchTree much easier. class TreeNode: def __init__(self, key): self.left = None self.right = None self.key = key self.data = None def insert(self, key): inserts a node with key into the correct position if not a duplicate. def find_successor(self): # returns the node that is the inorder successor of the node def find_min(self): # returns min value in the tree def find_max(self): # returns max value in the tree def inorder_print_tree(self) # print inorder the subtree of self def print_levels(self) #inorder traversal prints list of pairs, [key, level of the node] where root is level 0

class BinarySearchTree: def find (self, key): # returns True if key is in a node of the tree, else False def insert(self, newkey): def delete(self, key) # deletes the node containing key, assumes such a node exists def print_tree(self) # print inorder the entire tree def is_empty(self): #returns True if tree is empty, else False

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

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions