Question: Can you do this problem in Drracket code only. The answer should be exact what was mentioned below even the parenthesis should be exact. The

Can you do this problem in Drracket code only. The answer should be exact what was mentioned below even the parenthesis should be exact. The instructions goes like this: First part: Write a recursive function that given a number and a sorted binary tree, returns a sorted tree with the number inserted. The instructions for part goes like this: Part one is a recursive function tree-insert that takes a tree and a number and returns the tree with the number inserted.
(tree-insert 8()) should return (8)
(tree-insert 12'(8)) should return '(8((12)))
(tree-insert 3'(8)) should return '(8((3)()))
(tree-insert 12'(8((3)()))) should return '(8((3)(12)))
(tree-insert 4'(8((3)(12)))) should return '(8((3((4)))(12)))
Part 2: write a recursive function that given a list of numbers and a tree, returns a tree with all of the numbers inserted. The instructions of part 2 is:
Part two is another recursive function list-to-tree that takes a list of numbers and a sorted tree and inserts all of the numbers from the list into the tree. This function can be given an empty list as input for the sorted tree.
List-to-tree will repeatedly call tree-insert.
Test your function with:
(list-to-tree '(22257168346773217845319)())
Returns '(22((7((7((4((3)(5)))()))(16((8((8)()))(17((19)))))))(25((34((32)(67)))))))
Your function MUST match this output for any credit.
Numbers in the first subtree are less than or equal to the root node
Numbers in the second subtree are greater than the root node
'(6((3((2)(5)))(7((9))))) is a sorted binary tree
part 3: Write a recursive function that given a sorted tree, returns a list of numbers in ascending order. The instruction for part 3 is:
Part 3: Write a recursive function tree-to-list that given a sorted tree, constructs the list of numbers in order.
Test your function with:
(tree-to-list (list-to-tree '(22257168346773217845319)()))
list-to-tree should work as defined in the previous 2(part 1 and part 2)
This should return '(34577881617192225323467)
Tree-to-list should not call flatten or any sorting function.

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 Programming Questions!