Question
python BinarySearchTree easy question __init__(self) Initializes a tree node to be empty. Attribute values are set to None .. add(self, val) Adds a node with
python BinarySearchTree easy question
__init__(self)
Initializes a tree node to be empty. Attribute values are set to None..
add(self, val)
Adds a node with the value val to the tree so as to maintain the binary search tree property (see above).
find(self, val)
Returns: a reference to the tree node with value val if it exists, None otherwise.
__str__(self)
Returns a string representation of the tree. For the purposes of this assignment, this is defined as follows. Given a tree T:
If T is None (i.e., empty), return the string "None" (the quotation marks simply indicate that the value is a string; they are not part of the string itself).
Otherwise, suppose that T has a root node with value val and left and right subtrees Tleft and Tright. Return the string
"({:d} {} {})".format( val, str(Tleft), str(Tright))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started