Mini-project about multiplying integers in a tree using an accumulator

The goal of this mini-project is to spell out how to multiply integers in a tree using an accumulator by solving Exercise 2 from Week 12 in detail.

Warning

Exceptions are a topic of study in Week 12.

Question 1

Explain, in your own words, the structure and the rationale of the unit-test function in the accompanying file.

Question 2

Expand the unit-test function so that it does not just test the candidate function on one random binary tree of integers, but on a given number of random binary trees of integers.

(Hint: use repeat as defined in the accompanying file.)

Question 3

  1. Implement one more version of the multiplication function over binary trees, mult_v7, using an accumulator and no exception.
  2. Verify that your implementation passes the unit tests.
  3. Express your implementation using binary_tree_fold (which is defined in the accompanying file).
  4. Verify that your implementation passes the unit tests.

Question 4

  1. Implement one more version of the multiplication function over binary trees, mult_v8, using an accumulator and an exception.
  2. Verify that your implementation passes the unit tests.
  3. Express your implementation using binary_tree_fold (which is defined in the accompanying file).
  4. Verify that your implementation passes the unit tests.

Resources

Version

Fixed the spelling of binary_tree_fold, thanks to Ann Chen’s eagle eye [11 Apr 2021]

Created [03 Apr 2021]