August 27, 2024

P71 - Determine the internal path length of a tree.

We define the internal path length of a multiway tree as the total sum of the path lengths from the root to all nodes of the tree.  By this definition, the tree in the figure of problem P70 has an internal path length of 9.  Write a method internalPathLength to return that sum.

scala

scala> "afg^^c^bd^e^^^".internalPathLength
res0: Int = 9
Be first to comment
Leave a reply