Question: 3. (60 pts) Consider an implementation of binary trees with Scheme lists, as in the following example (define T 13 ' (13 17 25 (22

 3. (60 pts) Consider an implementation of binary trees with Scheme

3. (60 pts) Consider an implementation of binary trees with Scheme lists, as in the following example (define T 13 ' (13 17 25 (22 (17 )) 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-leaves T) 4 (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) 4 (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) (1 9 8 5 17 25 22 13) 3. (60 pts) Consider an implementation of binary trees with Scheme lists, as in the following example (define T 13 ' (13 17 25 (22 (17 )) 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-leaves T) 4 (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) 4 (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) (1 9 8 5 17 25 22 13)

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!