The most promising so far I have seen (which, admittedly, is not very long ...) is the Zipper Data Structure : This basically saves a separate structure, the way back from node to root, and makes local changes to this separate structure.
It can make several local changes, most of which are constant time, and write them back to the tree (restoring the path to the root, which are the only nodes that need to be changed) at a time.
Zipper is the standard library in Clojure (see the Zippers - Editing Functional Tree heading).
And there is original paper from Huet with implementation in OCaml.
Disclaimer: I programmed for a long time, but a couple of times I started working only with functional programming and did not even hear about the problem of functional editing of trees until last week, so there may well be other solutions I donβt know.
However, it seems that Zipper does most of what you could wish for. If there are other alternatives in O (log n) or lower, I would like to hear them.
source share