CSE3144 · Advanced Data Structures · Jul–Nov Semester 2026 · Lecture 30 of 36 · CO CSE3144.5

Persistent Data Structures

Every structure this semester has been ephemeral — modify it, and the old version is gone. What if every version stayed readable forever, at a cost far cheaper than copying the whole thing each time?

Dr. Manu ShrivastavaCourse Instructor · Consultation Fri 2–5 PM, LHC 308F
~115 minutesSession outcome: analyze partial and full persistence concepts
L30 · 00 — Agenda ~115 min

Every version, kept — for a fraction of the cost of copying

Why persistence?

00–08

What "ephemeral" has meant, silently, in every structure built so far.

Partial, full, and confluent persistence — definitions

08–16

Three precise levels of "how much of the past can you touch."

The naive approach, and the key insight

16–24

Full copying works but wastes almost everything that didn't change.

Path copying — concept

24–32

Copy only the nodes on the path to the change; share every other node, unmodified.

Animation: V0 → V1 (partial persistence, step one)

32–48

Every copy and every shared pointer, traced individually.

Animation: V1 → V2 (extending the chain)

48–62

Partial persistence in its natural habitat: a straight line of versions.

Animation: V0 → V1′ (full persistence, branching)

62–78

Going back to an OLDER version and modifying it too — legal only under full persistence.

The version graph, compared

78–86

A straight line vs. a branching tree, side by side.

Other approaches & complexity

86–98

Fat nodes, nodes-with-boxes, and the real cost of what we just built.

Applications & recap

98–115

Version control, functional languages, databases, and what's next.

CSE3144 — Lecture 30
L30 · 01 — Why persistence? ~8 min

Every structure so far has quietly destroyed its own past

"Ephemeral," made explicit

Every BST insertion, every heap extraction, every R-tree split this semester has modified the structure IN PLACE. Once you insert into a BST, the tree BEFORE that insertion is simply gone — overwritten. We call this an ephemeral data structure: only the current state exists.

What if the past needs to stay reachable?

An editor's undo history. A database that must answer "what did this row look like an hour ago." A version-control system. A functional programming language where variables never mutate. All of these need every past version of a structure to remain valid and queryable — not just the latest one. A persistent data structure is built to do exactly this, and (crucially) without paying the full cost of copying the entire structure on every single change.

CSE3144 — Lecture 30 · Why persistence
L30 · 02 — Partial, full, and confluent persistence ~8 min

Three precise levels of "how much of the past can you touch"

Partial persistence

All past versions can be READ, but only the NEWEST version can be modified. New versions form a straight LINE: V0 → V1 → V2 → …

Full persistence

Every version, past or present, can be BOTH read AND modified. Modifying an old version creates a new BRANCH. Versions form a TREE, not a line.

Confluent persistence

Two or more versions can be MERGED to form a new version. Versions form a DAG (a tree, but nodes may now have more than one parent) — today we focus on the first two, with confluent persistence as a natural extension.

Today's whole demonstration is one small BST, modified three different ways, specifically chosen so the SAME example shows a full partial-persistence chain and then a genuine full-persistence branch.

CSE3144 — Lecture 30 · Definitions
L30 · 03 — The naive approach, and the key insight ~8 min

Copying everything works. Copying almost nothing works better.

The naive approach: full copy

Before every modification, copy the ENTIRE structure, then modify the copy. This trivially achieves persistence — the old version is untouched by construction. But it costs O(size of structure) time and space for EVERY single update, even one that logically changes just one element.

The key insight: share what didn't change

Most updates touch only a small part of a structure. If we copy ONLY the parts that are actually affected, and let the new version SHARE every unaffected part with the old version (same node, same memory, referenced from both), we get persistence at a cost proportional to the SIZE OF THE CHANGE, not the size of the whole structure. For a tree, this technique is called path copying.

CSE3144 — Lecture 30 · Naive approach & key insight
L30 · 04 — Path copying — concept ~8 min

Copy the path to the change; share everything else

The rule

To insert a key into a BST while keeping the old version intact: walk from the root toward where the new key belongs. Every node ON that path gets a FRESH COPY (since its child pointer must change to point toward the new structure). Every node NOT on that path — every sibling subtree the path passes by — is simply referenced as-is by the new copies. It is never duplicated.

The cost

The number of new nodes created equals the length of the path from the root to the insertion point — the tree's HEIGHT. For a balanced BST, that's O(log n) new nodes per update, not O(n). Accessing version t just means remembering that version's own root pointer; everything below is either that version's own copies or shared structure from earlier versions.

CSE3144 — Lecture 30 · Path copying concept
L30 · 05 — Animation: V0 → V1 (partial persistence, step one) ~16 min

V0 = insert 50, 30, 70. Now insert 20 to create V1.

Every copy, and the one crucial shared pointer, shown as its own step.

Interactive — path-copy V0 into V1
CSE3144 — Lecture 30 · V0 → V1
L30 · 06 — Animation: V1 → V2 (extending the chain) ~14 min

Insert 60 into V1 (the newest version) to create V2

This is exactly what partial persistence permits: extend the LATEST version. V0 and V1 remain untouched and independently readable throughout.

Interactive — path-copy V1 into V2
CSE3144 — Lecture 30 · V1 → V2
L30 · 07 — Animation: V0 → V1′ (full persistence, branching) ~16 min

Go back to V0 — not V1 or V2 — and insert 80 instead

Under PARTIAL persistence this step would be illegal: V0 is no longer the newest version, so it could not be touched again. Under FULL persistence, any version may be modified — watch V0 grow a second child.

Interactive — path-copy V0 into an alternate V1′
CSE3144 — Lecture 30 · V0 → V1′
L30 · 08 — The version graph, compared ~8 min

A straight line vs. a branching tree

If we had stayed partially persistent

V0 → V1 → V2. One line. V0 could never be revisited for a NEW modification once V1 existed.

What we actually built: full persistence

V0 has TWO children, V1 and V1′. This branching is exactly what "every version can be modified" buys you — and it is precisely what a version-CONTROL system's branch/commit graph looks like.

CSE3144 — Lecture 30 · Version graph comparison
L30 · 09 — Other approaches & complexity ~12 min

Path copying is one technique among several

Fat nodes

Instead of copying nodes, make every node store its ENTIRE modification history (every past value of its key and pointers, each tagged with a timestamp). Reading version t means scanning a node's history for the most recent entry at or before t. Simple, but a node can grow arbitrarily "fat" and old reads can slow down.

Nodes with modification boxes

A refinement (Sleator & Tarjan): give each node a small, BOUNDED number of "modification boxes," each holding one pending change plus its timestamp. Once a node's boxes fill up, it gets copied (like path copying) — achieving amortized O(1) time and space per update, better than plain path copying's O(log n) for a tree.

TechniqueNew space per updateNotes
Full copy (naive)O(n)Simple, but defeats the purpose of sharing.
Path copying (today)O(h) = O(log n) for a balanced treeVerified today: exactly 3 new nodes per update, on a tree of height 2.
Nodes with modification boxesAmortized O(1)More complex to implement; used when updates vastly outnumber structural copies needed.

Access to any specific version costs whatever that version's own lookup would normally cost (O(log n) for a balanced BST) — persistence adds no asymptotic penalty to READING a version, only a controlled, small cost to CREATING a new one.

CSE3144 — Lecture 30 · Other approaches & complexity
L30 · 10 — Applications & recap ~17 min

Wherever "what did this look like before" must stay answerable

Version control systems

A commit graph IS a version tree: each commit shares nearly all its content with its parent, and branching a repository is exactly Section 07's "modify an older version" operation.

Functional programming languages

Immutable data structures in languages like Clojure and Scala (persistent vectors, maps, sets) are production implementations of exactly today's sharing principle — "modifying" a value returns a new one that shares almost all of its structure with the old.

Databases & editors

Multi-version concurrency control (MVCC) lets readers see a consistent snapshot while writers proceed, without locking; undo/redo stacks in editors are a simple partially-persistent version chain. Competitive programming also uses "persistent segment trees" for offline range-query problems across multiple array versions.

Lecture 31 — next

Disjoint Set Union (Union-Find)

CO CSE3144.5 — union by rank and path compression, the classic near-constant-time connectivity structure.

Homework — bring to Lecture 31
  • Starting from today's V2 (keys 20,30,50,60,70), path-copy an insertion of 65 to create V3. Show every copied node and every shared node.
  • Starting from today's V1′ (keys 30,50,70,80), path-copy an insertion of 90 to create a version V2′. Draw the FULL version graph after this: V0, V1, V2, V1′, V2′.
  • In 3–4 sentences: explain why path copying's cost is proportional to the tree's HEIGHT rather than the number of nodes it has, and why that stops being a good guarantee if the tree is badly unbalanced.
CSE3144 — Lecture 30

Questions?

Dr. Manu Shrivastava — LHC 308F — Friday 2:00–5:00 PM

Next: Lecture 31 — Disjoint Set Union (Union-Find).