1. Home
  2. Explore
  3. Computer Science
  4. Temporal Data Structures

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Temporal Data Structures

Persistent and Temporal Data Structures

The computational model: pointer machines

A pointer machine represents memory as a collection of nodes. Each node has a constant number of fields, and each field contains either data, a null pointer, or a pointer to another node. For the results discussed here, the data items themselves are treated as constant-size values.

The pointer machine supports operations such as:

  • Creating nodes.

  • Reading or changing fields.

  • Following pointers to reach other nodes.

  • Performing operations on stored data.

A distinguished root node provides the starting point for accessing the data structure. This model resembles linked objects or records in ordinary programming languages. It emphasizes how information is organized and reached through pointers, rather than the details of computation on the data.

For persistence results, two degree bounds matter:

  • Out-degree: the maximum number of pointers leaving a node, determined by its fields.

  • In-degree: the maximum number of pointers entering a node.

The general transformation results assume both are bounded by constants.


Temporal data structures and persistence

An ordinary data structure supports updates, which change its state, and queries, which inspect its state. A temporal data structure retains access to earlier states instead of discarding them.

A persistent update takes a specified version as input and produces a new version. The earlier version remains available, so it can still be queried and, depending on the persistence model, updated.

Persistence preserves previous versions of a data structure; an update creates a new version rather than destroying the old one.

Partial persistence

With partial persistence, only the newest version may be updated. Older versions remain available for queries but cannot be changed.

The versions therefore form a line:

  • An update of the current version creates a new current version.

  • Any older version can still be queried.

  • No update can branch from an older version.

Full persistence

With full persistence, any version may be updated. Updating an older version creates a new branch, while the original version and its descendants remain intact.

The versions form a tree:

  • Any version can be queried.

  • Any version can be used as the starting point of an update.

  • An update creates a new version without altering the version from which it branched.

Confluent persistence

With confluent persistence, two versions can be combined to create a new version. The version history can then form a directed acyclic graph (DAG) rather than a tree.

The meaning of “combine” depends on the data structure. For example, two lists might be concatenated, or two search trees might be joined. Confluence allows independently developed versions to be recombined, but it is substantially more difficult to support efficiently than ordinary full persistence.

Functional data structures

A functional data structure never modifies any node. Every update creates new nodes, while existing nodes remain unchanged.

This is stricter than persistence alone. A persistent implementation may alter internal nodes as long as all old versions continue to behave correctly; a functional implementation must preserve the old nodes themselves. If a data structure can be implemented functionally, its existing nodes and versions are automatically preserved, but the stricter requirement can make efficient implementations harder to find.

Retroactivity

Retroactive data structures provide a different kind of time travel: they allow changes to be made to the history of operations and then expose the consequences in the present. Persistence instead retains versions or branches without rewriting the history of a branch.


Partial persistence for pointer machines

A bounded-degree pointer-machine data structure can be made partially persistent with constant amortized overhead. The transformation preserves the data structure’s operations while retaining past versions.

The key is to record field changes rather than overwrite old values, and to copy a node when its record of changes becomes full.

Recording pointers with back pointers

For each pointer from one node to another, the target node stores a back pointer to the node and field containing that pointer. If a node has at most p incoming pointers, it needs at most p back pointers.

Back pointers make it possible to find and update the references to a node if its current representation must be replaced. In the partial-persistence construction, back pointers need only describe the latest version, because only that version can be updated.

Recording field changes with modifications

Each node stores:

  • Its original field values.

  • A bounded list of modifications, or mods.

A mod records three things:

  1. The version in which a field changed.

  2. Which field changed.

  3. The new value of that field.

The node’s original fields are not overwritten. Instead, each update appends a mod. For a node with at most p incoming pointers, the construction can use space for a constant number of mods, such as 2p.

Reading a field

To read a field in version v, the structure examines the node’s original value and its mods. It applies the latest mod to that field whose version is at or before v.

Since the number of mods per node is bounded by a constant, reading a field takes constant time.

Updating a field

When a field changes, the structure handles two cases:

  1. The mod record has room. It appends a mod containing the current version, field, and new value.

  2. The mod record is full. It creates a new node representing the latest state, including the changes recorded in the mods. The old node remains available to represent earlier versions. The structure then redirects the current version’s pointers to the new node.

Redirecting pointers requires finding all current references to the old node. Back pointers identify them. If changing one of those references causes another node to overflow, the same procedure is applied recursively.

Why the overhead is amortized constant

A simple update that appends a mod is cheap. An overflow can trigger copying and recursive pointer updates, so an individual operation may be expensive.

The analysis uses a potential function that measures how close the current representation is to overflowing. One natural choice is proportional to the total number of mods stored in nodes of the latest version. When a node fills and is replaced, its mod record is reset, causing a large drop in potential. That decrease pays for the copying and recursive work.

Consequently, although some updates take more than constant time, the total cost over a sequence of operations is linear in the number of operations: the amortized cost per update is constant.


Full persistence for pointer machines

Full persistence also admits constant amortized overhead for bounded-degree pointer-machine data structures. The construction resembles partial persistence, but the branching version history requires additional machinery.

Testing ancestry in the version tree

In full persistence, a mod applies to a queried version only if the mod’s version is an ancestor of that query’s version. Version numbers on a line are no longer sufficient, because the history branches.

A version tree can be represented by a traversal sequence:

  • Each version has a begin marker when the traversal first enters it.

  • Each version has an end marker when the traversal leaves it.

  • A version’s markers enclose the markers for its descendants.

The markers are kept in an order-maintenance structure, which supports inserting new markers into the maintained order and comparing the order of two markers in constant time. The interval between a version’s begin and end markers identifies its subtree. Thus, ancestry can be tested by checking whether one version’s interval contains another’s.

To read a field in version v, the structure finds the most recent applicable mod among those whose versions are ancestors of v.

Splitting a full node

The partial-persistence overflow strategy cannot be used unchanged. If an old version remains updateable, leaving its node full would allow repeated updates to trigger repeated copying.

Instead, when a node’s mod history fills, the construction splits the modification history into balanced portions:

  • One representation retains one portion of the history.

  • A new node represents another portion, corresponding to a subtree of versions.

  • Relevant changes are applied to the fields of the new node.

  • Pointers are redirected only in the versions represented by that new node; pointers in other versions continue to use the old representation.

Splitting gives the affected representations room for future mods. Although pointer redirection can recursively cause other nodes to be split, a potential function based on available mod capacity pays for that work. As in partial persistence, the result is constant amortized overhead under the bounded-degree assumptions.

Worst-case versus amortized guarantees

Amortized bounds permit some individual operations to be slow, provided the average cost over a sequence is low. For partial persistence, a deamortized construction achieves constant worst-case slowdown per operation. A corresponding worst-case result for full persistence was described as an open problem in the material.


Confluent persistence

Confluence makes it possible to combine versions, but it also makes version histories more complicated and can cause the logical size of a data structure to grow rapidly.

Splitting and concatenating lists

A list illustrates why confluent operations matter:

  1. Split a list into smaller lists.

  2. Concatenate selected lists in a new order.

  3. Reuse portions of the original versions to form new versions.

This supports operations analogous to copying and pasting text. If a list can be concatenated with itself, one update can double its logical length. Repeating this for u updates can produce a version whose length is as large as 2^u.

Such growth is possible because versions may share underlying nodes while representing data of much greater logical size. It makes it difficult to relate the number of updates to the amount of data represented.

Effective depth and a general result

One way to characterize the complexity of a confluent version is its effective depth. Conceptually, the version DAG is expanded into a tree by duplicating shared paths, and the number of paths reaching the version is counted. Effective depth is the logarithm of that path count.

A general transformation due to Fiat and Kaplan achieves overhead related to:

  • The logarithm of the number of updates.

  • The effective depth of the version involved.

In broad terms, an operation can incur a multiplicative cost depending on these quantities. If a sequence repeatedly combines a structure with itself, the number of paths can grow exponentially, making effective depth linear in the number of updates. The resulting overhead can therefore be large.

This can still be better than explicitly constructing the enormous final data structure, which may itself require exponential time and space. However, the guarantee is not a constant-overhead solution for all confluent operations.

A related lower bound shows that, for a particular data structure and construction, space—and hence update cost—must grow with effective depth if queries are treated as free. This lower bound is not a universal statement about every data structure or every confluent-persistence problem.

A central open question is whether general confluent persistence can achieve constant time and space overhead per operation when both updates and queries are charged.

A restricted result for disjoint combinations

A more favorable result is possible under a disjointness condition: a confluent operation may combine only versions that share no nodes. This rules out combining a structure with itself and prevents the most direct form of exponential duplication.

Under this restriction, the overhead can be logarithmic in the number of operations. The condition is substantial: combining versions with shared nodes is not covered by the guarantee.

The disjointness condition also gives a useful structural property. For a fixed underlying node, the versions containing that node form a tree, even though the complete version history is a DAG. This makes it possible to organize the node’s changes and determine which change applies to a given version. Techniques used in such analyses include:

  • Order maintenance, to keep version events ordered.

  • Link-cut trees, to locate relevant changes along a version history.

  • Fractional cascading, to speed up searches across related structures.

These techniques help control queries and updates within the restricted setting, but they do not by themselves resolve the general confluent-persistence problem.


Functional implementations and examples

Functional data structures provide another route to preserving versions. They can make persistence automatic, but their performance depends on whether updates can be implemented without rebuilding too much of the structure.

Balanced binary search trees by path copying

A balanced binary search tree can be made functional using path copying:

  1. Follow the search path to the location of the update.

  2. Copy each node on that path before changing it.

  3. Rebuild the path using the copied nodes.

  4. Leave all other nodes shared with the old version.

If the tree has n elements and height O(\log n), an update copies only O(\log n) nodes. This gives logarithmic-time updates while preserving the old tree. Implementations can avoid parent pointers, so the update does not need to modify shared nodes outside the copied path.

Deques

A deque is a double-ended queue: elements can be inserted or removed at either end. Deques can also support concatenation in constant time per operation in suitable functional implementations.

Constant-time splitting is more difficult. Efficiently supporting both split and concatenate for lists or deques is an example of an open challenge highlighted in the material.

Tries and versioned directory structures

A trie is a tree with a fixed branching structure, similar to a directory hierarchy. A versioned directory system can copy a subtree from one version into another, producing a DAG of versions. This is a practical example of confluent-style sharing.

Functional or confluent implementations can achieve strong bounds for some such structures, but the exact bounds depend on properties such as node degree and on the allowed operations. Functional implementations are not automatically optimal merely because they preserve old nodes.

The cost of functional immutability

Functional data structures can be slower than unrestricted mutable data structures because an update may need to copy nodes rather than change them in place. In general, known examples can exhibit a logarithmic-factor gap between functional and unrestricted implementations. The gap illustrates the trade-off: immutability simplifies version preservation, but can impose extra work on updates.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent