Question
6. Consider the following type of trees of integers: type product_tree = { value: int ; children: product_tree list ; product: int option } Each
6. Consider the following type of trees of integers: type product_tree = { value: int ; children: product_tree list ; product: int option } Each node contains an integer (value) and zero or more child nodes (children). It also contains an optional product field, to store the product of all of the integers in a node. (i) Write a function are same : product_tree -> product_tree -> bool that checks whether the two product_tree arguments are equal, except possibly for the product fields. (ii) Write a function get_product : product_tree -> int that computes the product of the values in a tree. You should use the product fields to avoid performing multiplications as much as possible. Assume that you can trust these fields. I.e., even if this field contains a wrong value, you may use it. (iii) Write function fill_products : product_tree -> product_tree such that fill_products t returns the same tree as t, but with all of the product fields filled in (so the result should not contain None). Again you should avoid unnecessary multiplications as much as possible. a
6. Consider the following type of trees of integers: type product_tree = { value: int ; children: product_tree list ; product: int option } Each node contains an integer (value) and zero or more child nodes (children). It also contains an optional product field, to store the product of all the values in the subtree rooted by this node locally at the node. (i) Write a function are same : product_tree -> product_tree -> bool that checks whether the two product_tree arguments are equal, except possibly for the product fields. (ii) Write a function get_product : product_tree -> int that computes the product of the values in a tree. You should use the product fields to avoid performing multiplications as much as possible. Assume that you can trust these fields. I.e., even if this field contains a wrong value, you may use it. (iii) Write function fill_products : product_tree -> product_tree such that fill_products t returns the same tree as t, but with all of the product fields filled in (so the result should not contain None). Again you should avoid unnecessary multiplications as much as possible. a 6. Consider the following type of trees of integers: type product_tree = { value: int ; children: product_tree list ; product: int option } Each node contains an integer (value) and zero or more child nodes (children). It also contains an optional product field, to store the product of all the values in the subtree rooted by this node locally at the node. (i) Write a function are same : product_tree -> product_tree -> bool that checks whether the two product_tree arguments are equal, except possibly for the product fields. (ii) Write a function get_product : product_tree -> int that computes the product of the values in a tree. You should use the product fields to avoid performing multiplications as much as possible. Assume that you can trust these fields. I.e., even if this field contains a wrong value, you may use it. (iii) Write function fill_products : product_tree -> product_tree such that fill_products t returns the same tree as t, but with all of the product fields filled in (so the result should not contain None). Again you should avoid unnecessary multiplications as much as possible. aStep 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