Difference between revisions of "99 questions/Solutions/71"

From HaskellWiki
Jump to navigation Jump to search
 
(categorize)
 
Line 8: Line 8:
 
where ipl' d (Node _ ts) = d + sum (map (ipl' (d+1)) ts)
 
where ipl' d (Node _ ts) = d + sum (map (ipl' (d+1)) ts)
 
</haskell>
 
</haskell>
  +
  +
[[Category:Programming exercise spoilers]]

Latest revision as of 03:52, 10 January 2017

(*) 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, tree5 has an internal path length of 9.

ipl :: Tree a -> Int
ipl = ipl' 0
  where ipl' d (Node _ ts) = d + sum (map (ipl' (d+1)) ts)