Question: Implement the check _ bst _ validity ( ) function in the BSTChecker.py file. The function takes the tree's root node as a parameter and
Implement the checkbstvalidity function in the BSTChecker.py file. The function takes the tree's root node as a parameter and returns the node that violates BST requirements, or None if the tree is a valid BST
A violating node will be one of three things:
A node in the left subtree of an ancestor with a lesser key
A node in the right subtree of an ancestor with a greater key
A node with the left or right attribute referencing an ancestor
The given code in main.py reads and parses input, and builds the tree for you. Nodes are presented in the form key leftchild, rightchild where leftchild and rightchild can be nested nodes or None. A leaf node is of the form key After parsing tree input, the checkbstvalidity function is called and the returned node's key or "None" is printed.If the input is:
None,
which corresponds to the tree above, then the output is:
because violates BST requirements by being in the left subtree of def checkbstvalidityrootnode:don't change this function header. this must be in PYTHON
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
