Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. Consider the following type of trees of integers: type product_tree = { value: int ; children: product_tree list ; product: int option } Each

image text in transcribed

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. a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

What environmental factors influenced achievement?

Answered: 1 week ago

Question

Data points include: state assessments including subgroups

Answered: 1 week ago