Answer by Will Ness for Haskell: tail recursion version of depth of binary tree
to your 3., yes, e.g. by use of CPS technique (as shown in Chris's answer); to your 4., correct. to your 2., with lazy corecursive breadth-first tree traversal we naturally get a solution similar to...
View ArticleAnswer by Ingo for Haskell: tail recursion version of depth of binary tree
A partially tail recursive version would be this: depth d Empty = d depth d (Branch _ l Empty) = depth (d+1) l depth d (Branch _ Empty r) = depth (d+1) r depth d (Branch _ l r) = max (depth (d+1) l)...
View ArticleAnswer by Chris Taylor for Haskell: tail recursion version of depth of binary...
1. Why isn't your function tail recursive? For a recursive function to be tail recursive, all the recursive calls must be in tail position. A function is in tail position if it is the last thing to be...
View ArticleHaskell: tail recursion version of depth of binary tree
First of all I have two different implementation that I believe are correct, and have profiled them and thinking they are about of the same performance: depth::Tree a -> Int depth Empty = 0 depth...
View Article