Bug 1: Modifying shared nodes Never modify a node that might be shared.
Always create a new node. // WRONG node.value := newValue // RIGHT newNode := copy(node) newNode.value := newValue Bug 2: Wrong version indexing Version 0 is usually the initial state.
After updates, latest is version . Bug 3: Forgetting to store roots Each version needs its root stored.
Don't overwrite the roots array. Bug 4: Null pointer in queries Persistent trees can have null children (sparse). Handle in queries. Time: . Space: .