Help Count nodes

#1

I need to count the nodes of a tree implemented as follows:
sealed trait[+A]
case class LeafA extends Tree[A]
case class Branch[A](left: Tree[A], rigth: Tree[A]) extends Tree[A]

#2

What’s the signature of the method you’d like to implement? What have you tried so far?

#3

With a DFS travesal, in a recursive way. For each Branch, if left is a Leaf, that is the “path” end, so try the right with the same “Node Count”. In other case (it sound like pattern matching :stuck_out_tongue_winking_eye:), add another node to the count and repeat.