Question: class AVLNode ( BSTNode ) : AVL Tree Node class. Inherits from BSTNode DO NOT CHANGE THIS CLASS IN ANY WAY
class AVLNodeBSTNode: AVL Tree Node class. Inherits from BSTNode DO NOT CHANGE THIS CLASS IN ANY WAY def initself value: object None: Initialize a new AVL node DO NOT CHANGE THIS METHOD IN ANY WAY # call init from parent class superinitvalue # new variables needed for AVL self.parent None self.height def strself str: Override string method DO NOT CHANGE THIS METHOD IN ANY WAY return 'AVL Node: formatselfvalue class AVLBST: AVL Tree class. Inherits from BST def initself starttreeNone None: Initialize a new AVL Tree DO NOT CHANGE THIS METHOD IN ANY WAY # call init from parent class superinitstarttree def strself str: Override string method DO NOT CHANGE THIS METHOD IN ANY WAY values superstrhelperselfroot, values return "AVL preorder joinvalues def isvalidavlself bool: Perform preorder traversal of the tree. Return False if there are any problems with attributes of any of the nodes in the tree. This is intended to be a troubleshooting 'helper' method to help find any inconsistencies in the tree after the add or remove operations. Review the code to understand what this method is checking and how it determines whether the AVL tree is correct. DO NOT CHANGE THIS METHOD IN ANY WAY stack Stack stack.pushselfroot while not stack.isempty: node stack.pop if node: # check for correct height relative to children left node.left.height if node.left else right node.right.height if node.right else if node.height maxleft right: return False if node.parent: # parent and child pointers are in sync if node.value node.parent.value: checknode node.parent.left else: checknode node.parent.right if checknode node: return False else: # NULL parent is only allowed on the root of the tree if node self.root: return False stack.pushnoderight stack.pushnodeleft return True # # def addself value: object None: TODO: Write your implementation pass
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
