Data Structures19 sections · 729 units
Open in Course

The Path Copying Technique

Core method for trees

When updating a tree node, copy only the path from root to that node.

Original tree (version 0):
      A
     / \
    B   C
   / \
  D   E

Update D to D' (version 1):
Create new A', B', point to D' and old E, C

      A'            A
     / \           / \
    B'  C         B   C
   / \           / \
  D'  E         D   E

Version 0 root: A. Version 1 root: A'.

Both versions share nodes C and E.

Space per update: O(logn)O(\log n) for balanced trees (one node per level).