Answered step by step
Verified Expert Solution
Link Copied!

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!

image text in transcribedimage text in transcribed

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

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago