Question: Can someone write these 2 functions 1. Compose and 2. Trim using tree_fold(given) and without using any recursive helper functions in Ocaml. type 'a tree

 Can someone write these 2 functions 1. Compose and 2. Trim

using tree_fold(given) and without using any recursive helper functions in Ocaml. type

'a tree = | Node of 'a tree * 'a * 'a

Can someone write these 2 functions 1. Compose and 2. Trim using tree_fold(given) and without using any recursive helper functions in Ocaml.

type 'a tree = | Node of 'a tree * 'a * 'a tree | Leaf let rec tree_fold f init tree = match tree with | Leaf init Node (1,v,r)f( tree_fold f init 1 ) v (tree_fold f init r ) trim tree n - Type: ('a tree int 'a tree) - Description: Using tree_fold write a function that takes in a complete binary tree tree and an integer n, and trims off nodes at the bottom of the tree such that the depth of the returned tree is at most n - Examples: let tree = Node(Node(Node(Leaf, 4, Leaf), 2, Node(Leaf, 4, Leaf)), 1, Node(Node(Leaf, 4, Leaf), 2, Node(Leaf, 4, Leaf))) in trim tree 1=Node( Leaf, 1, Leaf); trim tree 2=Node(Node(Leaf,2,Leaf),1,Node(Leaf,2,Leaf)) compose tree - Type: ((a ' ) tree ' a ' ) - Description: This function will take in a tree that contains ( aa) functions as the value in the nodes and returns a function that is the inorder composition of the nodes. You must implement this function using tree_fold. - Examples: Consider the following diagram of a tree. The result of calling compose on this function would be equivalent to (ffunxh(y(f(g(vx))))) let function_tree = Node( Node(Leaf,(funx>x+1),Leaf),(funx>xx), Node(Leaf, (fun xx+xx), Leaf)) let composed = compose function_tree composed = composed 1=12 letcomposed2composed22composed215=composeLeaf=2=15

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!