From ec003e03a58716424e98ec32a94e2f9fc9dcaa1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0krob=C3=A1nek?= <jiri.skrobanek@gmail.com> Date: Mon, 26 Jul 2021 23:56:37 +0200 Subject: [PATCH] Annotate path-copying --- 201-persist/persist.tex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/201-persist/persist.tex b/201-persist/persist.tex index 96ebc64..83d2d65 100644 --- a/201-persist/persist.tex +++ b/201-persist/persist.tex @@ -59,6 +59,10 @@ Pointers in new vertices are updated to point to new copies of corresponding ver The root of the newly created version is the copy of the original root. Thus the new version now shares some vertices with the old version. Here we tacitly assume that only pointers to children are stored. Updating the root in a tree with pointers to parents would involve creating copies for all nodes in the tree. +Insertion of a vertex G is depicted in figure \figref{path-copying}. +We can see an original tree with vertices A, B, C, D, E, F. +The thick vertices are created by the insert operation. + This method yields a functional data structure since the old version of the tree was technically not modified and can still be used. With reasonable variants of binary search trees, achieved time complexity in a tree with $n$ vertices is $\Theta(\log n)$ per operation and $\Theta(\log n)$ memory for insert/delete. @@ -66,7 +70,6 @@ The downside of this method is the increased space complexity. There is no apparent construction that would not increase memory complexity by copying the paths. \figure[path-copying]{path-copying.pdf}{}{Path copying} -% TODO: Annotate This outlined method is not exclusive to binary search trees. It may be used to obtain functional variants of more variants of pointer data structures, of which binary search trees are a prime example. -- GitLab