Question: 3. In lab this week, you wrote some functions to work with binary trees. In this question, you will develop some code for binary search

 3. In lab this week, you wrote some functions to work

3. In lab this week, you wrote some functions to work with binary trees. In this question, you will develop some code for binary search trees, as we have been doing in lecture. The representation of a binary search tree will be the same as the binary trees we used in lab, that is, a tree is a three-element list: the value of the node, the left subtree, and the right subtree, with empty trees represented as the empty list. Unlike the binary search trees we have been discussing in lecture, for the questions here we will assume all of the values are strings, so you will need to use the comparison functions string , string>?, and string-? functions to build and search through your trees. Note: For all of the binary search tree problems in 3 and 4, you should work with the data in the tree (or trees), and not extract the data from the tree into a list and solve the problem on the list. While that strategy could work, you would lose the advantages of having the data in a binary search tree, and will not get credit for these even if the code passes the Mimir tests (a) Using your tree functions, write a Scheme function (bst-element? item bs-tree) that evaluates to #t if item is the value of a node in bs-tree. #f otherwise. (b) Using these functions, write a Scheme function (bst-insert item bs-tree) that evalu- ates to the binary search tree that that results from inserting the value item into binary search tree bs-tree. Remember that we do not allow duplicate values in our binary search trees (c) Write the Scheme function (bst-smallest bs-tree) that evaluates to the smallest value in binary search tree bs-tree. If there are no values in the tree, it should evaluate to 'undefined) (d) Write the Scheme function (bst-largest bs-tree) that evaluates to the largest value in binary search tree bs-tree. If there are no values in the tree, it should evaluate to undefined) (e) Define a Scheme procedure, named bst-equal?, which takes two binary search trees as parameters and returns true if the trees are identical (same values in the same places with the same structure) and false otherwise. (f) Since these binary search trees contain strings (their node values) without repeats, they are ideal for representing sets of strings. Write a Scheme function (bst-subset? bst1 bst2) that evaluates to #t if the set of values in bst 1 is a subset of the set of values in bst2, #f otherwise (g) Use bst-subset to write a Scheme function (bst-set-equal? bst1 bst2), that evalu- ates to #t if the set of values in bstl is the same as the set of values in bst2, #f otherwise

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!