Pure functional bottom up tree algorithm
Posted
by Axel Gneiting
on Stack Overflow
See other posts from Stack Overflow
or by Axel Gneiting
Published on 2010-05-22T07:44:41Z
Indexed on
2010/05/22
7:50 UTC
Read the original article
Hit count: 244
Say I wanted to write an algorithm working on an immutable tree data structure that has a list of leaves as its input. It needs to return a new tree with changes made to the old tree going upwards from those leaves.
My problem is that there seems to be no way to do this purely functional without reconstructing the entire tree checking at leaves if they are in the list, because you always need to return a complete new tree as the result of an operation and you can't mutate the existing tree.
Is this a basic problem in functional programming that only can be avoided by using a better suited algorithm or am I missing something?
© Stack Overflow or respective owner