What are Retroactive Data Structures?
Last Updated :
08 Mar, 2021
Retroactive Data structures are a type of data structure that supports efficient modifications performed on a data structure, in this new data structuring paradigm, the operations performed on the data structure are not only in present but also in the past which means the operations can be altered and modified even in the pastime interval.
These data structures give us great comfort in terms of flexibility while working on complex applications that need regular updates as adjusting the structure can be adjusted according to the working model of the program, in the real world there are various cases where there is a need to modify a past operation from a sequence of operations.
Need For Retroactive Data Structures:
- For Implementing Dynamization: Generally, some algorithms that are in static nature demand a dynamic data structure to process their input and retroactive data structure can be the best solution for making these algorithms dynamic.
- For performing Approximate Range Searching: Retroactive data structures help in implementing operations that require updates like insert and delete at any point of time and to return the input in an approximate range of time t.
- To avoid extra O(log n) Overhead: Retroactive data structures help us in avoiding extra O(log n) overhead and enables applications to perform operations such as building a high-degree segment tree over segments, Augmenting root with traditional data structures, Augment nodes with CDFC structures.
- Altering historical sequence of transactions: Retroactive data structures make the applications efficiently adaptable to conditions such as undo of errors that were previously made without redoing all the work since then.
Comparison With Persistent Data Structures:
Even though the notion of persistent data structures and retroactive data structures may look similar as they take the dimension of time into account, still the way they handle the element of time makes them stand different from each other.
- A persistent data structure maintains several versions of data structures and the operation can be implemented on one version of data to create another version.
- In the case of retroactive data structures, changes are made directly to previous versions and there is no creation of other modified previous versions that were subjected to data change in the past.
Types of Retroactivity:
1. Partially Retroactive: Any data structure can be made partially retroactive by general transformations. For example, the following inserts a partially retroactive list with an initial state [1,2,3,4,5]. We can then add or remove the operation in present.
Below is the Python pseudo-code for the above concept:
# Python program to implement
# the above approach
x = PartiallyRetroactive([1, 2, 3, 4, 5])
def appendOne(lst):
return lst + [1]
# Three appendOnes by applying
# insertAgo()
x.insertAgo(appendOne, tminus = 0)
x.insertAgo(appendOne, tminus = 0)
x.insertAgo(appendOne, tminus = 0)
x.query()
# Three appendOnes by applying insertAgo()
[1, 2, 3, 4, 5, 1, 1, 1]
Output:
>>x.query() :
[1, 2, 3, 4, 5, 1, 1, 1]
We can also add or remove operations from the past:
def MethodForAppendNum(lst):
return lst + [6]
## For Inserting into *two* operations ago
a.insertAgo(appendSix, tminus=2)
a.query()
[1, 2, 3, 4, 5, 1, 6, 1, 1]
## For Deleting the first appendOne
a.deleteAgo(tminus=3)
a.query()
[1, 2, 3, 4, 5, 6, 1, 1]
Output:
>>a.query() :
[1, 2, 3, 4, 5, 1, 6, 1, 1]
2. General Full Retroactivity: Full Retroactive data structures are similar to their siblings Partial Retroactive Data Structures, in that they permit retroactive insertion and deletion of operations. However, fully-retroactive data structures also permit querying into the past instead of just the present.
Below is the Python pseudo-code for the above approach:
b = MethodForFullyRetroactive([1,2,3])
b.insertAgo(appendOne, tminus = 0)
## This one should come last
b.insertAgo(appendSix, tminus = 0)
## This one should come first
b.insertAgo(appendTen, tminus =2)
b.query()
## The current state of the data structure
[1, 2, 3, 10, 1, 6]
b.query(1)
[1, 2, 3, 10, 1]
b.query(2)
[1, 2, 3, 10]
b.query(3)
## The state of the data structure way back
## in the past
[1, 2, 3]
Output:
>>b.query(1) :
[1, 2, 3, 10, 1, 6]
>>b.query(2) :
[1, 2, 3, 10]
>>b.query(3) :
[1, 2, 3]
Applications: Some applications of retroactive data structures are listed below
- Recovery: If we have a hardware chip that was damaged and the data on it was lost, but it was now repaired, and we can read data from the sensor, and we want data to be inserted back into the system as if the hardware was never damaged.
- Error Correction: In case of incorrect input of data, the data must be corrected and the secondary effects of the wrong input must be eliminated.
- Data Manipulation in pastime intervals: Modifying data in pastime can help in the prevention of damage control in cases where false data has been injected due to system error or manual error.
- Bad Data: When dealing with entering data in a large system particularly in systems such as sensors in weather network malfunctions which take large amounts of automated data transfer, garbage and incorrect data could cause great damage to applications, the ideal solution will be removing bad data in past operations by using retroactive data structures to create a scenario like if bad data never occurred.
Advantages Of Retroactive Data Structures:
- Provides us flexibility in correcting time-based updates without the use of cost-effective rollback operations whenever a data crash happens.
- These data structures can be most effectively applied for searching problems such as maintaining set k of some unknown objects which are subjected to operations like insert, delete, and query(x, s) as here we can have the privilege of modifying the data structure by going back again in time sequence and retrieving our desired query.
- These data structures help us in solving decomposed search problems like performing queries of the form query(x, AuB) = f(query(x, A), query(x, B)) which runs in O(1) time.
- They help to dynamize static Algorithms effectively.
Disadvantages of Retroactive Data Structures:
- These data structures demand high storage and computing resources as they run in higher polynomial times.
- These data structures work fine on complex applications that thrive solely on time-based updates without proper order based objectives but not recommended on simple and scalable applications that generate strict-rule based timely updates like Employee Attendance Management System, One-Time password generator because implementing this data structure can create bugs for changing and modifying the information.
- Involves high maintenance costs due to the execution of high polynomial transformations.
- If the applications implemented with Retroactive data structures were not covered with effective encryption-algorithm standards, then there is a high chance for intentional data manipulation that can not be even traced as there will be no time records available.
Automatic Retroactivity: There comes a natural doubt in our minds about the possibility of converting data structures automatically into retroactive form by using a general technique for example like converting a pointer-machine model into an effective partially retroactive data structure? Such a general technique would nicely complement existing persistence data structures but in the case of retroactive data structures, the retroactivity is fundamentally different from persistence, and generally known techniques do not apply.
One simple approach to this general problem is the rollback method, where auxiliary information is stored as all changes for the data structures are made by each operation in such a way that each change could be reversed dynamically, For example, to enable a rollback for the memory-write operation we store the value that was previously at the address, therefore their performances act differently depending upon the retroactive change.
Retroactive Running Times: Take a number of operations performed by the data structure for determining the running time of retroactive data structures. For example, let m be a number of operations performed on the structure and let r be numbers of operations performed before the retroactive operations, and n be the maximum number of elements present in the structure at any time.
Similar Reads
Introduction to Data Structures
What is Data Structure?A data structure is a particular way of organising data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. The choice of a good data structure makes it possible to perform a variety of critical operations
7 min read
What is Data Structure?
A data structure is a way of organizing and storing data in a computer so that it can be accessed and used efficiently. It refers to the logical or mathematical representation of data, as well as the implementation in a computer program. Classification:Data structures can be classified into two broa
2 min read
Introduction to Linear Data Structures
Linear Data Structures are a type of data structure in computer science where data elements are arranged sequentially or linearly. Each element has a previous and next adjacent, except for the first and last elements. Characteristics of Linear Data Structure:Sequential Organization: In linear data s
8 min read
Introduction to Augmented Data Structure
Data Structures play a significant role in building software and applications but many a times all our requirements are not satisfied using an existing data structure. This is when we modify an existing data structure according to our needs. This article will provide a brief introduction about when
10 min read
Getting Started with Array Data Structure
Array is a collection of items of the same variable type that are stored at contiguous memory locations. It is one of the most popular and simple data structures used in programming. Basic terminologies of ArrayArray Index: In an array, elements are identified by their indexes. Array index starts fr
14 min read
Persistent data structures
All the data structures discussed here so far are non-persistent (or ephemeral). A persistent data structure is a data structure that always preserves the previous version of itself when it is modified. They can be considered as âimmutableâ as updates are not in-place. A data structure is partially
15 min read
Stack Data Structure
A Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
3 min read
Static and Dynamic Data Structures
Data structures are the fundamental building blocks of computer programming. They determine how data is organized, stored, and manipulated within a software application. There are two main categories of data structures: static and dynamic. Static data structures have a fixed size and are allocated i
9 min read
Is array a Data Type or Data Structure?
What is Data Type? In computer programming, a data type is a classification of data that determines the type of values that can be stored, manipulated, and processed. It tells the computer what kind of data a particular variable or constant can hold, and what operations can be performed on that data
8 min read
What is Stack Data Structure? A Complete Tutorial
Stack is a linear data structure that follows LIFO (Last In First Out) Principle, the last element inserted is the first to be popped out. It means both insertion and deletion operations happen at one end only. LIFO(Last In First Out) PrincipleHere are some real world examples of LIFO Consider a sta
4 min read