Question: pls fast ocaml programming language Define a function weighted_total_depths of type int tree -> int in hw4_trees.ml such that weighted_total_depths t returns the weighted total

 pls fast ocaml programming language Define a function weighted_total_depths of type

pls fast

ocaml programming language

Define a function weighted_total_depths of type int tree -> int in hw4_trees.ml such that weighted_total_depths t returns the weighted total depths of the nodes inside the tree t). The elements in the tree are weights, and the root element is at depth 1. For example, the following tree has the weighted total depths 52 x1 + 21 x 2 + 43 x 2 +96 x 3 = 468. Immediately ask questions on Piazza if you are unsure about how the total depths were calculated. The goal of this task is to discover good recursive formulas and implement them in OCaml; the concept weighted total depths is interesting but not the main point. 52 21 43 96 weighted_total_depths Leaf ===> 0 weighted_total_depths (Branch (Leaf, 1000, Leaf)) ===> 1000 weighted_total_depths (Branch (Branch (Leaf, 1, Leaf), 2, Branch (Leaf, 3, Leaf))) ===> 10 weighted_total_depths (Branch (Branch (Branch (Leaf, 96, Leaf), 21, Leaf), 52, Branch (Leaf, 43, Leaf))) ===> 468

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!