Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In programming language Scheme, perform the questions. Write the answers neatly.

ID: 3869978 • Letter: I

Question

In programming language Scheme, perform the questions. Write the answers neatly. Correct answer for all parts will get a rating!

Consider an implementation of binary trees with Scheme lists, as in the following example: (define T 13 (13 (5 25 (22 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) (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)

Explanation / Answer

a)

search(Note root,Node node)

{ if(root==node)return true;

}

if(root->left)

{

search(root.left(),node);

}

if(root->right)

{

search(root.Right(),node);

}

}

b) Preorder:

void preorder(struct binarytreenode *root)

{

if(root)

{

printf("%d",root->data);

preorder(root->left);preorder(root->right)

}

}

C:In order

void inorder(struct binarytreenode *root)

{

inorder(root->left);

printf("%d",root->data);

inorder(root->right);

}

}