Snippets tagged tail recursion

  • sum the nodes in a (not-binary) tree using continuations

    you can easily find how to use continuations to iterate over a binary tree but what if the count of children for each node is not known at design time? It's not so obvious how to do this in order to get a tail-recursive method. This short snippet shows how to do this to sum the values of every leaf. The second part demonstrates a general approach for other operations than addition.

    25 people like this

    Posted: 6 years ago by Carsten K├Ânig

  • Factorial

    Factorial versus tail recursion

    3 people like this

    Posted: 4 years ago by Laco