Question: These have to be implemented using the Scheme programming language. I already have the building blocks made : (define (val T) (car T) ) (define

These have to be implemented using the Scheme programming language. I already have the building blocks made :

(define (val T) (car T) )

(define (left T) (car (cdr T)) )

(define (right T) (car (cdr (cdr T))) )

Consider an implementation of binary trees with Scheme lists, as in the following example: (define T ' (13 (5 (1 () ()) (8 () (9 () ()))) (22 (17 () ())(25 () ())))) Before proceeding, it may be useful to define three auxiliary functions (val T), (left T) and (right T), which return the value in the root of tree T, its left subtree and its right subtree, respectively. (a) Write a recursive function (tree-member? V T), which determines whether V appears as an element in the tree T. The following example illustrates the use of this function: > (tree-member? 17 T) #t (b) Write a recursive function (preorder T), which returns the list of all elements in the tree T corresponding to a preorder traversal of the tree. The following example illustrates the use of this function: > (preorder T) (13 5 1 8 9 22 17 25) (c) Write a recursive function (inorder T), which returns the list of all elements in the tree T corresponding to an inorder traversal of the tree. The following example illustrates the use of this function: > (inorder T) (1 5 8 9 13 17 22 25)

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!