Question: ocaml pls quick Define a function expand_tree of type 'a tree -> 'a tree in hw4_trees.ml such that expand_tree t returns a new tree by

ocaml pls quick

ocaml pls quick Define a function expand_tree of type 'a tree ->

'a tree in hw4_trees.ml such that expand_tree t returns a new tree

Define a function expand_tree of type 'a tree -> 'a tree in hw4_trees.ml such that expand_tree t returns a new tree by replacing each element in the original tree t with three copies of that element. See below for more details. (Note: the "replacing" here does not mean assignment or changing the input tree in OCaml. It is merely a thought process to describe the final tree you should generate. In fact, OCaml would not allow you to change the input tree, so you will be very stuck if you attempt to modify the input. It just would not work, and such restriction is a blessing in disguise.) Here's the diagrammatic representation of the operation. Assume that we have a node as in the following diagram with the value x: x It will be replaced by a group of three nodes with the same value x shown as follows. The right subtree then becomes the right subtree of the right subtree, and the left subtree becomes the left subtree of the left subtree. The dashed line only represents the conceptual grouping--- it does not correspond to anything in the actual tree. X X X For example, let's assume the input tree looks like this: 1 For example, let's assume the input tree looks like this: 1 2 4. 3 The function expand_tree should return a tree that looks like this: 1 1 1 2 4 2 2 4 4 3 3 3 Here are some sample input-output pairs: expand_tree Leaf ===> Leaf expand_tree (Branch (Leaf, "root", Leaf)) ===> Branch (Branch (Leaf, "root", Leaf), "root", Branch (Leaf, "root", Leaf)) expand_tree (Branch (Branch (Leaf, 2.718, Leaf), 3.142, Leaf)) ===> Branch (Branch (Branch (Branch (Leaf, 2.718, Leaf), 2.718, Branch (Leaf, 2.718, Leaf)), 3.142, Leaf)

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!