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

Speaker 1Speaker 2

Temporal Data Structures

15:09
0:00-15:09
  1. Maria

    Welcome to Advanced Data Structures. The big idea is that familiar structures—like balanced search trees—are only the beginning. We’ll ask how data structures behave in different models of computation, and how to handle problems such as changing data over time, higher-dimensional geometry, hashing, integer keys, dynamic graphs, text search, and storing information in very few bits.

  2. Anna

    And the model matters because it determines what an algorithm is allowed to do. Today we’re starting with a pointer machine: think of memory as nodes, each with a constant number of fields. A field can hold data, a null pointer, or a pointer to another node.

  3. Maria

    You can create nodes, inspect and change fields, follow pointers, and do computations on the data. For today, the important part is how the memory is organized; we won’t need to manipulate the data values in any complicated way. There’s also a root node that gives us a starting point for reaching the rest of the structure.

  4. Anna

    That model fits a lot of classic data structures, including linked structures and search trees. We’re going to take an existing pointer-machine data structure and ask whether we can transform it so that it remembers its past.

  5. Maria

    That brings us to temporal data structures. There are two different kinds of time travel in this material: persistence and retroactivity. Persistence means keeping old versions around; retroactivity means going back, changing something, and then seeing the consequences in the present. Retroactivity is the topic of the next lecture, so today we’ll focus on persistence.

  6. Anna

    In a persistent structure, each update takes a particular version and creates a new version. An update might insert an item, for example. The old version remains available, so you can query it later instead of losing it.

  7. Maria

    There are several levels of persistence. The simplest is partial persistence: you may update only the latest version, but you can query any version, including old ones. The versions therefore form a line, or timeline.

  8. Anna

    Full persistence lets you update any version. If you go back to an earlier version and make a change, that change creates a new branch rather than replacing the history that was already there. The versions form a tree, and all of them can still be queried.

  9. Maria

    Confluent persistence goes further: you can combine two versions to create a new one. When versions branch and later combine, their relationships form a directed acyclic graph, or DAG. What combining means depends on the data structure—for instance, two linked lists might be concatenated.

  10. Anna

    And functional data structures are even more restrictive at the level of memory: you never modify any nodes. You only create new ones. Since old nodes cannot be destroyed, old versions are preserved, and partial, full, and confluent persistence all follow from that immutability.

  11. Maria

    The distinction is subtle but useful. Ordinary persistence only requires that every version continue to behave correctly when queried; it doesn’t require representing the old version with exactly the same nodes as before. Functional structures do require that nodes themselves remain unchanged, which can make it harder to achieve the fastest running times.

  12. Anna

    Let’s see how partial persistence works. A result from Driscoll, Sarnak, Sleator, and Tarjan says that a pointer-machine structure can be made partially persistent with constant amortized-factor overhead, plus a constant amount of extra space per change, provided each node has only a constant number of incoming pointers as well as a constant number of fields.

  13. Maria

    The incoming-pointer condition is important. The transformation stores back pointers: whenever one node points to another, the target keeps a pointer back to the source. If only a constant number of pointers can point into a node, its back pointers also take constant space and can be followed in constant time.

  14. Anna

    Then, instead of overwriting a field whenever it changes, we keep its original value and record modifications. A modification says which version the change belongs to, which field changed, and the new value. To read a field in a requested version, we inspect the original value and the constant-size list of changes, applying the latest change that occurred by that version.

  15. Maria

    Each node can hold only a constant number of modifications. If there’s room, changing a field is easy: add one record. The interesting case is when the node’s modification list is full.

  16. Anna

    When it’s full, we make a new node representing the latest state of the old one. We apply the stored changes to the new node, so its modification list starts empty, and leave the old node in place to represent earlier versions. That preserves the past without forcing the new version to keep using a full node.

  17. Maria

    But pointers in the latest version that used to point to the old node must now point to the new one. Back pointers tell us where those incoming pointers are, so we can find them. Updating an ordinary pointer is itself a field change, though, so it may trigger this same procedure recursively.

  18. Anna

    That recursion sounds as if it could spread through the whole structure. The reason it doesn’t ruin the amortized bound is that a full node is expensive only when it has accumulated many modifications. When we replace it, its new representative starts with an empty list.

  19. Maria

    Exactly. A potential function can measure the number of modifications in the nodes used by the latest version. Adding a modification raises the potential by a constant amount. Replacing a full node clears its list, lowering the potential enough to pay for the pointer updates and recursive work it caused.

  20. Anna

    So the occasional expensive operation is paid for by the work that filled the node in the first place. Across a sequence of operations, the amortized cost stays constant-factor overhead. That is the heart of the partial-persistence result.

  21. Maria

    There’s a small bookkeeping point about versions, too. A version can be identified by its root—the place where a search or query begins. In a real implementation, you keep track of the root associated with each version. The pointer-machine analysis itself doesn’t use arrays, so that kind of version lookup is separate bookkeeping.

  22. Anna

    Now, full persistence uses much of the same machinery, but two things change. First, back pointers have to be maintained across all versions, not just the latest one. Second, versions are no longer linearly ordered, so we can’t decide which modifications apply by simply comparing timestamps.

  23. Maria

    To handle that second issue, represent the version history as a tree. For each version, mark its beginning and end in a traversal of the tree. The entire subtree rooted at a version lies between those two marks, much like a matched pair of parentheses.

  24. Anna

    A version v is an ancestor of version w exactly when w’s beginning and end both fall between v’s beginning and end. If we can maintain the ordering of those marks and compare two items in constant time, we can test the ancestor relationship in constant time.

  25. Maria

    That’s what an order-maintenance data structure provides. It supports inserting a new item immediately before or after a specified item, and it answers which of two items comes first. When a new version is created, we insert its beginning and ending marks into the right place.

  26. Anna

    Now a modification applies to a version if the version where the change happened is an ancestor of the version we’re querying. The beginning-and-ending marks let us test that. So, just as in partial persistence, a field can be read by considering its stored modifications—but now we use ancestry in the version tree instead of a timestamp comparison.

  27. Maria

    The harder difference comes when a node’s modifications are full. In partial persistence, making a fresh node for the latest version solves the problem, because we only update the latest version. In full persistence, we might keep updating the same old version, so that old node could remain full and repeatedly cause expensive copying.

  28. Anna

    The fix is to split the modifications into two balanced groups. Conceptually, the modifications form a tree, and we separate it into roughly equal-sized parts. One node represents one part of the history, and a new node represents the other.

  29. Maria

    We apply the changes relevant to the newer part to the new node’s fields, while retaining the modifications needed to represent the other histories. Then we redirect the pointers for the versions that belong to the new node’s part of the history. The old node continues to represent the versions that still need it.

  30. Anna

    Redirecting those pointers can again cause recursive changes. But the split creates room in the modification lists. A potential function based on empty modification slots drops when the split happens, and that decrease pays for the pointer updates and recursion.

  31. Maria

    So the full-persistence result is also constant-factor amortized overhead for pointer-machine structures under the constant-degree conditions. It’s a clever combination of back pointers, recorded changes, version ancestry, and balanced splitting.

  32. Anna

    Amortized bounds do mean that a particular operation can be slower than the original operation, with later operations balancing it out. For partial persistence, there is also a deamortized result: the overhead can be made constant in the worst case for every operation.

  33. Maria

    For full persistence, the corresponding worst-case constant-overhead result was left as an open problem in this material. That’s a good reminder that changing from a timeline to a branching history can introduce genuinely harder questions.

  34. Anna

    Confluent persistence is harder still. Now versions form a DAG, and it’s much harder to put the history into a useful linear order. More importantly, combining versions can make a data structure grow very quickly.

  35. Maria

    Imagine a text editor where you can split a string into pieces and concatenate pieces to make a new version. You can use those operations to copy and paste, or even concatenate a string with itself. Each such doubling takes only a constant number of operations, but after u doublings the structure can contain 2 to the u elements.

  36. Anna

    That exponential growth is why confluent persistence is both powerful and challenging. The result described by Fiat and Kaplan measures a version’s effective depth: roughly, take the version DAG, expand shared histories into a tree of paths, count the paths leading to that version, and take the logarithm.

  37. Maria

    Their general transformation has a multiplicative time and space overhead that depends on the logarithm of the number of updates and on the effective depths of the versions involved. In a sequence with exponentially many paths, that logarithm can be linear in the number of updates, so the overhead may be linear.

  38. Anna

    Fiat and Kaplan also give a space lower bound for a particular data structure: in the worst case, the space can have to grow with a version’s effective depth. A key detail is how the work is charged. Their example performs many queries before an update, so if queries are free in the accounting and only updates are charged for space, the update may have to bear that overhead.

  39. Maria

    That leaves an open question: if we charge both queries and updates, can general confluent persistence be achieved with constant time and space overhead per operation? The material presents this as an unresolved challenge.

  40. Anna

    There’s a more favorable result under a restriction. A later result assumes that a confluent operation combines two versions that have no nodes in common. That rules out self-concatenating a version with itself, but still permits pieces to be rearranged and recombined.

  41. Maria

    Under that disjointness assumption, the overhead can be logarithmic in the number of operations. The intuition is that, when you focus on one node, the versions containing it have a tree-like structure rather than repeatedly merging copies that share that same node.

  42. Anna

    The analysis uses additional tools to navigate that history. One case is handled by a structure called link-cut trees, and another uses fractional cascading. The important point here is that these are supporting techniques for the restricted result, not a general constant-overhead solution.

  43. Maria

    Let’s finish with functional data structures. A simple example is a balanced binary search tree. If you implement updates from the root downward and don’t use parent pointers, you can copy each node on the path you change, along with its ancestors.

  44. Anna

    A balanced tree has only logarithmic height, so path copying takes logarithmic time. The untouched parts of the tree can be shared between versions, while the copied path gives the new version its own nodes. That makes functional balanced search trees a straightforward example.

  45. Maria

    Another example is a deque, a double-ended queue where you can insert and delete at both ends. Functional deques can also support concatenation in constant time per operation. Constant-time splitting is harder and was presented as an open problem.

  46. Anna

    Tries provide a different example: they have a fixed tree-like topology, much like a directory tree. A version-control system can copy a subtree from one version into another, producing a version DAG. There are theoretical ways to make such operations efficient, although practical constant factors can still be a barrier.

  47. Maria

    More broadly, the known gap between functional data structures and ordinary data structures can be a factor of logarithmic n in the worst case. Improving that separation is another open direction.

  48. Anna

    So the progression is: partial persistence keeps a timeline of queryable versions; full persistence lets the history branch; confluent persistence lets branches merge; and functional structures never modify nodes at all. Each step offers more flexibility or stronger guarantees, but the implementation and analysis become more challenging.

  49. Maria

    And that’s the central lesson of this introduction to temporal data structures: the way you represent memory and history matters. With pointer-machine techniques, recorded modifications, back pointers, and careful amortized analysis, persistence can be added efficiently in important settings—while confluent persistence still leaves fascinating open problems.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent