Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago