Order-maintenance problem
In Computer Science the Order-Maintenance Problem involves maintaining a totally ordered set supporting the following operations:
insert(X, Y)
, which inserts X immediately after Y in the total order;order(X, Y)
, which determines if X precedes Y in the total order; anddelete(X)
, which removes X from the set.
The first data structure for order-maintenance was given by Dietz in
1982.[1] This data
structure supports insert(X, Y)
in
amortized time and order(X, Y)
in constant time but does
not support deletion. Tsakalidis published a data structure in 1984
based on BB[α] trees with the same performance bounds that supports
deletion in and showed how indirection can be
used to improve insertion and deletion performance to
amortized time.[2] In 1987 Dietz and Sleator published the first data
structure supporting all operations in worst-case constant time.[3][4]
Efficient data structures for order-maintenance have applications in many areas, including data structure persistence,[5] graph algorithms[6][7] and fault-tolerant data structures. [8]
List-Labeling
A problem related to the order-maintenance problem is the
list-labeling problem in which instead of the order(X,
Y)
operation the solution must maintain an assignment of labels
from a universe of integers to the
elements of the set such that X precedes Y in the total order if and
only if X is assigned a lesser label then Y. It must also support an
operation label(X)
returning the label of any node X.
Note that order(X, Y)
can be implemented simply by
comparing label(X)
and label(Y)
so that any
solution to the list-labeling problem immediately gives one to the
order-maintenance problem. In fact, most solutions to the
order-maintenance problem are solutions to the list-labeling problem
augmented with a level of data structure indirection to improve
performance. We will see an example of this below.
For efficiency, it is desirable for the size of the universe be bounded in the number of elements stored in the data structure. In the case where is required to be linear in the problem is known as the packed-array maintenance or dense sequential file maintenance problem. Consider the elements as entries in a file and the labels as giving the address where each element is stored. Then an efficient solution to the packed-array maintenance problem would allow efficient insertions and deletions of entries into the middle of a file with no asymptotic space overhead.[9][10][11][12][13] This usage has recent applications in cache-oblivious data structures[14] and optimal worst-case in-place sorting.[15]
However, under some restrictions, lower bounds have been found on the performance of insertion in solutions of the list-labeling problem with linear universes[16] whereas we will see below that a solution with a polynomial universe can perform insertions in time.
List-Labeling and Binary Search Trees
List-labeling in a universe of size polynomial in the number of elements in the total order is connected to the problem of maintaining balance in a binary search tree. Note that every node X of a binary search tree is implicitly labeled with an integer that corresponds to its path from the root of the tree. We call this integer the path label of X and define it as follows. Let be the sequence of left and right descents in this path. For example, if X is the right child of the left child of the left child of the root of the tree. Then X is labeled with the integer whose base 3 representation is given by replacing every occurrence of in with 0, replacing every occurrence of in with 2 and appending 1 to the end of the resulting string. Then in the previous example, the path label of X is 00213 which is equal to 7 in base 10. Note that path labels preserve tree-order and so can be used to answer order queries in constant time.
If the tree has height then these integers come from
the universe . Then if the
tree is self-balancing so that
it maintains a height no greater than then the
size of the universe is polynomial in .
Therefore, the list-labeling problem can be solved by maintaining a balanced binary search tree on the elements in the list augmented with path labels for each node. However, since every rebalancing operation of the tree would have to also update these path labels, not every self-balancing tree data structure is suitable for this application. Note, for example, that rotating a node with a subtree of size , which can be done in constant time under usual circumstances, requires path label updates. In particular, if the node being rotated is the root then the rotation would take time linear in the size of the whole tree. With that much time the entire tree could be rebuilt. We will see below that there are self-balancing binary search tree data structures that cause an appropriate number of label updates during rebalancing.
Data structure
The list-labeling problem can be solved with a universe of size polynomial in the number of elements by augmenting a scapegoat tree with the path labels described above. Scapegoat trees do all of their rebalancing by rebuilding subtrees. Since it takes time to rebuild a subtree of size , relabeling that subtree in time after it is rebuilt does not change the asymptotic performance of the rebalancing operation.
Order
Given two nodes X and Y, order(X, Y)
determines their
order by comparing their path labels.
Insert
Given a new node for X and a pointer to the node Y, insert(X,
Y)
inserts X immediately after Y in the usual way. If a
rebalancing operation is required, the appropriate subtree is rebuilt,
as usual for a scapegoat tree. Then that subtree is traversed depth
first and the path labels of each of its nodes is updated. As
described above, this asymptotically takes no longer than the usual
rebuilding operation.
Delete
Deletion is performed similarly to insertion. Given the node X to be
deleted, delete(X)
removes X as usual. Any subsequent
rebuilding operation is followed by a relabeling of the rebuilt
subtree.
Analysis
It follows from the argument above about the rebalancing performance of a scapegoat tree augmented with path labels that the insertion and deletion performance of this data structure are asymptotically no worse than in a regular scapegoat tree. Then, since insertions and deletions take amortized time in scapegoat trees, the same holds for this data structure.
Furthermore, since a scapegoat tree with parameter α maintains a height of at most , the path labels have size at most . For the typical value of then the labels are at most .
Of course, the order of two nodes can be determined in constant time by comparing their labels. A closer inspection shows that this holds even for large . Specifically, if the word size of the machine is bits, then typically it can address at most nodes so that . It follows that the universe has size at most and so that the labels can be represented with a constant number of (at most ) bits.
Lower bound on list-labeling
It has been shown that any solution to the list-labeling problem with a universe polynomial in the number of elements will have insertion and deletion performance no better than .[17] Then, for list-labeling, the above solution is asymptotically optimal. (Incidentally, this also proves an lower bound on the amortized rebalancing time of an insertion or deletion in a scapegoat tree.)
However, this lower bound does not apply to the order-maintenance problem and, as stated above, there are data structures that give worst-case constant time performance on all order-maintenance operations.
O(1) amortized insertion via indirection
Indirection is a technique in data structures in which a problem is split into multiple levels of a data structure in order to improve efficiency. Typically, a problem of size is split into problems of size . For example, in y-fast tries. A similar strategy works to improve the insertion and deletion performance of the data structure described above to constant amortized time. In fact, this strategy works for any solution of the list-labeling problem with amortized insertion and deletion time.
Specifically, instead of storing the elements of the total order directly in the tree, we split them up into contiguous sublists each of size . We store nodes representing each of these sublists in the tree in their original list order. For each sublist we maintain a doubly-linked list of its elements, storing with each element a pointer to its representative in the tree as well as a local integer label, independent of the labels used in the tree. These labels are used to compare any two elements of the same sublist. Initially, we give the elements of each sublist are given the local labels . This uniform labeling will not be maintained strictly, however. Instead, the sublists will be periodically rebuilt.
See also
References
- ^ Dietz, Paul F. [http://dx.doi.org/10.1145/800070.802184 "Maintaining order in a linked list."] In Proceedings of the fourteenth annual ACM symposium on Theory of computing, pp. 122-127. ACM, 1982.
- ^ Tsakalidis, Athanasios K. [http://dx.doi.org/10.1007/BF00289142 "Maintaining order in a generalized linked list."] Acta informatica 21, no. 1 (1984): 101-112.
- ^ Dietz, Paul, and Daniel Sleator. [http://dx.doi.org/10.1145/28395.28434 "Two algorithms for maintaining order in a list"]. In Proceedings of the nineteenth annual ACM symposium on Theory of computing, pp. 365-372. ACM, 1987.
- ^ Dietz, P., D. Sleator, [http://www.cs.cmu.edu/~sleator/papers/maintaining-order.html Two algorithms for maintaining order in a list], Carnegie Mellon University Computer Science technical report CMU-CS-88-113, 1988
- ^ Driscoll, James R., Neil Sarnak, Daniel D. Sleator, and Robert E. Tarjan. [http://dx.doi.org/10.1016/0022-0000(89)90034-2 "Making data structures persistent."] Journal of computer and system sciences 38, no. 1 (1989): 86-124.
- ^ Eppstein, David, Zvi Galil, Giuseppe F. Italiano, and Amnon Nissenzweig. [http://dx.doi.org/10.1145/265910.265914 "Sparsification—a technique for speeding up dynamic graph algorithms."] Journal of the ACM (JACM) 44, no. 5 (1997): 669-696.
- ^ Katriel, Irit, and Hans L. Bodlaender. [http://dx.doi.org/10.1145/1159892.1159896 "Online topological ordering."] ACM Transactions on Algorithms (TALG) 2, no. 3 (2006): 364-379.
- ^ Aumann, Yonatan, and Michael A. Bender. [http://dx.doi.org/10.1109/SFCS.1996.548517 "Fault tolerant data structures."] In Foundations of Computer Science, 1996. Proceedings., 37th Annual Symposium on, pp. 580-589. IEEE, 1996.
- ^ Itai, Alon, Alan Konheim, and Michael Rodeh. [http://dx.doi.org/10.1007/3-540-10843-2_34 "A sparse table implementation of priority queues."] Automata, Languages and Programming (1981): 417-431.
- ^ Dan E Willard. Inserting and deleting records in blocked sequential files. TechnicalReport TM81-45193-5, Bell Laboratories (1981).
- ^ Willard, Dan E. [http://dx.doi.org/10.1145/800070.802183 "Maintaining dense sequential files in a dynamic environment."] In Proceedings of the fourteenth annual ACM symposium on Theory of computing, pp. 114-121. ACM, 1982.
- ^ Willard, Dan E. [http://dx.doi.org/10.1145/16894.16879 "Good worst-case algorithms for inserting and deleting records in dense sequential files."] In ACM SIGMOD Record, vol. 15, no. 2, pp. 251-260. ACM, 1986.
- ^ Willard, Dan E. [http://dx.doi.org/10.1016/0890-5401(92)90034-D "A density control algorithm for doing insertions and deletions in a sequentially ordered file in a good worst-case time."] Information and Computation 97, no. 2 (1992): 150-204.
- ^ Bender, Michael A., Erik D. Demaine, and Martin Farach-Colton. [http://dx.doi.org/10.1137/S0097539701389956 "Cache-oblivious B-trees."] SIAM Journal on Computing 35, no. 2 (2005): 341-358.
- ^ Franceschini, Gianni, and Viliam Geffert. [http://dx.doi.org/10.1145/1082036.1082037 "An In-Place Sorting with O (n log n) Comparisons and O (n) Moves."] Journal of the ACM (JACM) 52, no. 4 (2005): 515-537.
- ^ Dietz, Paul, and Ju Zhang. [http://dx.doi.org/10.1007/3-540-52846-6_87 "Lower bounds for monotonic list labeling."] SWAT 90 (1990): 173-180.
- ^ Dietz, Paul, Joel Seiferas, and Ju Zhang. [http://dx.doi.org/10.1007/3-540-58218-5_12 "A tight lower bound for on-line monotonic list labeling."] Algorithm Theory—SWAT'94 (1994): 131-142.
External links
- Two simplified algorithms for maintaining order in a list. - This paper presents a list-labeling data structure with amortized performance that does not explicitly store a tree. The analysis given is simpler than the one given by (Dietz and Sleator, 1987) for a similar data structure.
- Open Data Structures - Chapter 8 - Scapegoat trees