Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following problem must be written in scheme- thank you! 3. (60 pts) Consider an implementation of binary trees with Scheme lists, as in the
The following problem must be written in scheme- thank you!
3. (60 pts) Consider an implementation of binary trees with Scheme lists, as in the following example: (define T 13 '(13 (5 5 (1 8 17 25 90 0)) (22 (17 ) (25 O))) Before proceeding, it may be useful to define three auxiliary functions (left T), (right T) and (val T) which return the left subtree, the right subtree, and the value in the root of tree T, respectively. (a) (15 pts) Write a recursive function (n-nodes T), which returns the number of nodes in the tree T. The following example illustrates the use of this function: >(n-nodes T) (b) (15 pts) Write a recursive function (n-leaves T), which returns the number of leaves in the tree T. The following example illustrates the use of this function: > (n-leavesT) (c) (15 pts) The height of a tree is defined as the maximum number of nodes on a path from the root to a leaf. Write a recursive function (height T), which returns the height of the tree T. The following example illustrates the use of this function: > (height T) (d) (15 pts) Write a recursive function (postorder T), which returns the list of all elements in the tree T corresponding to a postorder traversal of the tree. The following example illustrates the use of this function: >(postorder T) (198 5 17 25 22 13)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