Question: Consider the following scala definitions Trait Tree Case object Leaf extends Tree case class Node (1:Tree, n:Int, r:Tree) extends Tree def f (ts:List[Tree]) : Int

Consider the following scala definitions

Trait Tree Case object Leaf extends Tree case class Node (1:Tree, n:Int, r:Tree) extends Tree

def f (ts:List[Tree]) : Int = { ts match { case Nil => 0 case Leaf :: us => f (us) case Node (1, n, r) :: us => f (1 :: (r :: us)) + n } }

Which one of the following statements is true 1) the function f is tail recursive 2) the function f is not tail recursive because of the addition 3) the function f is not tail recursive because of the cons on the right -hand side of the third case 4) the function f is not tail recursive because it uses binary trees instead of lists 5) The function f des not compile becasue it fails typechecking

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!