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.Paul Dietz first introduced a data structure to solve this problem in1982.[1] This datastructure supports insert(X, Y)
in
O(logn)
order(X, Y)
in constant time but doesnot support deletion. Athanasios Tsakalidis used BB[α] trees with the same performance bounds that supportsdeletion in O(logn)
O(1)
Efficient data structures for order-maintenance have applications inmany areas, including data structure persistence,[4] graph algorithms[5] [6] and fault-tolerant data structures.[7]
See main article: List-labeling problem. A problem related to the order-maintenance problem is thelist-labeling problem in which instead of the order(X,
Y)
operation the solution must maintain an assignment of labelsfrom a universe of integers
\{1,2,\ldots,m\}
label(X)
returning the label of any node X.Note that order(X, Y)
can be implemented simply bycomparing label(X)
and label(Y)
so that anysolution to the list-labeling problem immediately gives one to theorder-maintenance problem. In fact, most solutions to theorder-maintenance problem are solutions to the list-labeling problemaugmented with a level of data structure indirection to improveperformance. We will see an example of this below.For a list-labeling problem on sets of size up to
n
m
n
m=n1+\Theta(1)
O(logn)
2\Omega(n)
Indirection is a technique used in data structures in which a problemis split into multiple levels of a data structure in order to improveefficiency. Typically, a problem of size
n
n/logn
logn
O(logn)
The new data structure is completely rebuilt whenever it grows toolarge or too small. Let
N
\tfrac{N}{3}\len\le2N
During the rebuilding operation, the
N
O(N/logN)
\Omega(logN)
m=N2
O(logN)
For each sublist adoubly-linked list of its elements is built storing with each element apointer to its representative in the tree as well as a local integerlabel. The local integer labels are also taken from a range
m=N2
\Theta(logN)
m
O(1)
See the list-labeling problem for details of both solutions.
Given the sublist nodes X and Y, order(X, Y)
can beanswered by first checking if the two nodes are in the samesublist. If so, their order can be determined by comparing their locallabels. Otherwise the labels of their representatives in the first list-labeling problem are compared. These comparisons take constant time.
Given a new sublist node for X and a pointer to the sublist node Y,insert(X, Y)
inserts X immediately after Y in the sublistof Y, if there is room for X in the list, that is if the length of the list is no greater than
2logN
O(1)
If the local list overflows, it is split evenly into two lists of size
logN
This sequence of operations take
O(logN)
\Omega(logN)
O(1)
Given a sublist node X to be deleted, delete(X)
simplyremoves X from its sublist in constant time. If this leaves thesublist empty, then we need to remove the representative of thelist of sublists. Since at least
\Omega(logN)
O(logN)
O(1)