Question: CSc 120: Binary Search Trees Expected Behavior Implement a clas Binarye that hehaves as specifind belaw instances of this class should satisfy the binay soach

 CSc 120: Binary Search Trees Expected Behavior Implement a clas Binaryethat hehaves as specifind belaw instances of this class should satisfy the

CSc 120: Binary Search Trees Expected Behavior Implement a clas Binarye that hehaves as specifind belaw instances of this class should satisfy the binay soach tee proporty Namely, for cvcry node in the tree, the values in the left subtrec should all be smaller than the valuc at that node; and the valucs in the right sulbtroc should all be bigger than a binary search tree is gwen ?n he nrture nntes. he value a th at no e o create a hinary search ree, hm in wrth an emp y ree anc repea nr y insert values into ? he ale n hm nr inserti a value in Attributes tach node in the troe should have a val (an integeri) as well as references to the left and right subtrees. The names for the attributes are up to you. Methods Your class shauld implement (at least the following methods: -init--(self) acdd self, val) find(self, val) Initializes a tree nocle to be empty. Attribute values are set to None. Adds a node with the value val to the tree so as to maintain the binary scarch tree property (see above). Returns: a reference tn the tree ncde with value w! ?f it exists. None ntherwise. -str.(selt) Retuns a string representation of the tree. For the purposes of this assignment, this is clefined as follows. Given a tree T HT is None (ie, empty return the string "None' the quotation marks sin p y indicate that the value isa string; they are not part of the sti ng tset. . Otherwise, suppose thatT has a root node with value vai and left and right subtrees T ert and T,itt. Return the string Gotchas to watch out for he cuce shown ?n he class eclure no es or binary search rees ?? or u binay search trees. no me hu s or a c ass. This problem as s yuu u write ne uds o' a class he difference ha methods are invu ked on ob ec s in his case these ob ec s ate c CSc 120: Binary Search Trees Expected Behavior Implement a clas Binarye that hehaves as specifind belaw instances of this class should satisfy the binay soach tee proporty Namely, for cvcry node in the tree, the values in the left subtrec should all be smaller than the valuc at that node; and the valucs in the right sulbtroc should all be bigger than a binary search tree is gwen ?n he nrture nntes. he value a th at no e o create a hinary search ree, hm in wrth an emp y ree anc repea nr y insert values into ? he ale n hm nr inserti a value in Attributes tach node in the troe should have a val (an integeri) as well as references to the left and right subtrees. The names for the attributes are up to you. Methods Your class shauld implement (at least the following methods: -init--(self) acdd self, val) find(self, val) Initializes a tree nocle to be empty. Attribute values are set to None. Adds a node with the value val to the tree so as to maintain the binary scarch tree property (see above). Returns: a reference tn the tree ncde with value w! ?f it exists. None ntherwise. -str.(selt) Retuns a string representation of the tree. For the purposes of this assignment, this is clefined as follows. Given a tree T HT is None (ie, empty return the string "None' the quotation marks sin p y indicate that the value isa string; they are not part of the sti ng tset. . Otherwise, suppose thatT has a root node with value vai and left and right subtrees T ert and T,itt. Return the string Gotchas to watch out for he cuce shown ?n he class eclure no es or binary search rees ?? or u binay search trees. no me hu s or a c ass. This problem as s yuu u write ne uds o' a class he difference ha methods are invu ked on ob ec s in his case these ob ec s ate c

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!