Question: ( 2 points ) Consider the integer tree type type t r e e = | L e a f | Node of t r

(2 points) Consider the integer tree type
type t r e e =
| L e a f
| Node of t r e e i n t t r e e
The simplest way to calculate the sum of an integer tree is:
l e t r e c sum t = match t with
| L e a f >0
| Node ( l , v , r )> sum l + v + sum r
However, this implementation is not tail-recursive. Write a tail recursive function sumtailrec
: tree > int that sums up the integer values in a tree. (Hint: Use an auxiliary function of
type: int > tree list > int ).

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!