prev
to store the value of the previously visited node during the traversal, initially set to None
.inorder
that accepts a node and the prev
variable.None
, return True
(base case for recursion).inorder
on the left child of the node.prev
is not None
and the value of prev
is greater than or equal to the current node's value, return False
.prev
to the current node's value.inorder
on the right child of the node.True
, the tree is a valid BST.