Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. (10 pts) Given the following ML declarations of a binary tree type with integers in the leaf nodes and of five functions operating on
2. (10 pts) Given the following ML declarations of a binary tree type with integers in the leaf nodes and of five functions operating on trees datatype tree-L of int leaf with an integer) I N of tree tree node with two subtrees) fun max (n, m)if n> m then n else m fun a (L i) 1a(N (1, r) ) = a 1 + a r fun b (L i) l b (N (, max (bl, b r) fun c (L i) I c (N(1, r)-c1 cr fun d (L i) Id(N(1, r)) = 1 + d 1 + d r Eun e (L ) e (N (1, r)) = 1 + max (e 1, e r) In each function definition, the first line is the case for a leaf node (i.e., the base case of the recursion). and the second line recursively calls the function for the left and right subtrees. These functions compute: the height of the tree, and the number of leaves in the tree, e the sum of all the values in the leaves, the number of interior nodes in the tree, the maximum value of any leaf node in the tree. Associate the functions with their descriptions. Try it first without typing them in
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