List-labeling problem

In computer science, the list-labeling problem involves maintaining a totally ordered set S supporting the following operations:


 * , which inserts X into set S;
 * , which removes X from set S;
 * , which returns a label assigned to X subject to:
 * $$\in \{0, 1, \ldots, m-1\}$$
 * $$\forall$$ X,Y $$\in$$ S, X < Y implies

The cost of a list labeling algorithm is the number of label (re-)assignments per insertion or deletion. List labeling algorithms have applications in many areas, including the order-maintenance problem, cache-oblivious data structures, data structure persistence,. graph algorithms. and fault-tolerant data structures..

Sometimes the list labeling problem is presented where S is not a set of values but rather a set of objects subject to a total order. In this setting, when an item is inserted into S, it is specified to be the successor of some other item already in S. For example, this is the way that list labeling is used in the order-maintenance problem. The solutions presented below apply to both formulations.

Upper bounds
The cost of list labeling is related to $$m$$, the range of the labels assigned. Suppose that no more than $$n$$ items are stored in the list-labeling structure at any time. Four cases have been studied:
 * $$ m = 2^{\Omega(n)}$$
 * $$ m = n^{\Omega(1)}$$
 * $$ m = O(n) $$
 * $$ m = (1+\varepsilon) n $$

Exponential Labels
In the exponential label case, each item that is inserted can be given a label that is the average of its neighboring labels. It takes $$\Omega(n)$$ insertions before two items are at adjacent labels and there are no labels available for items in between them. When this happens, all items are relabelled evenly from the space of all labels. This incurs $$O(n)$$ relabeling cost. Thus, the amortized relabeling cost in this case is $$O(1)$$.

Polynomial Labels
The other cases of list labeling can be solved via balanced binary search trees. Consider $$T$$, a binary search tree on S of height $$h$$. We can label every node in the tree via a path label as follows: Let $$\sigma(X)$$ be the sequence of left and right edges on the root-to-$$X$$ path, encoded as bits. So if $$X$$ is in the left subtree of the root, the high-order bit of $$\sigma(X)$$ is $$0$$, and if it is in the right subtree of the root, the high-order bit of $$\sigma(X)$$ is $$1$$. Once we reach $$X$$, we complete $$\sigma(X)$$ to a length of $$h+1$$ as follows. If $$X$$ is a leaf, we append $$0$$s as the low order bits until $$\sigma(X)$$ has $$h+1$$ bits. If $$X$$ is an internal node, we append one $$0$$ and then $$1$$s as the low order bits until $$\sigma(X)$$ has $$h+1$$ bits.

The important properties of $$\sigma$$ are that: these labels are in the range $$\{0, 1, \ldots, 2^{h+1}-1\}$$; and for two nodes with keys $$X$$ and $$Y$$ in $$T,$$ if $$X<Y,$$ then $$\sigma(X) < \sigma(Y)$$. To see this latter property, notice that the property is true if the least common ancestor of $$X$$ and $$Y$$ is neither $$X$$ nor $$Y$$, because $$\sigma(X)$$ and $$\sigma(Y)$$ will share bits until their least common ancestor. If $$X<Y$$, then because $$T$$ is a search tree, $$X$$ will be in the left subtree and will have a next bit of $$0$$, whereas $$Y$$ will be in the right subtree and will have a next bit of $$1$$.

Suppose instead that, without loss of generality, the least common ancestor of $$X$$ and $$Y$$ is $$X$$, and that $$X$$ has depth $$d$$. If $$Y$$ is in the left subtree of $$X$$, then $$\sigma(X)$$ and $$\sigma(Y)$$ share the first $$d+1$$ bits. The remaining bits of $$\sigma(X)$$ are all 1s, whereas the remaining bits of $$\sigma(Y)$$ must have a $$0$$, so $$\sigma(Y)<\sigma(X)$$. If instead $$Y$$ is in the right subtree of $$X$$, then $$\sigma(X)$$ and $$\sigma(Y)$$ share the first $$d$$ bits and the $$d+1$$st bit of $$\sigma(X)$$ is $$0$$, whereas the $$d+1$$st bit of $$\sigma(Y)$$ is $$1$$. Hence $$\sigma(X)<\sigma(Y)$$.

We conclude that the $$\sigma$$ function fulfills the monotonicity property of the  function. Thus if we can balance the binary tree to a depth of $$(\log m) -1$$, we will have a solution to the list labeling problem for labels in the range $$\{0,\ldots,m-1\}$$.

Weight-balanced trees
In order to use a self-balancing binary search tree to solve the list labeling problem, we need to first define the cost function of a balancing operation on insertion or deletion to equal the number of labels that are changed, since every rebalancing operation of the tree would have to also update all path labels in the subtree rooted at the site of the rebalance. So, for example, rotating a node with a subtree of size $$k$$, which can be done in constant time under usual circumstances, requires $$\Omega(k)$$ 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.

A weight-balanced tree BB[$$\alpha$$] is defined as follows. For every $$X$$ in a root tree $$T$$, define $$size(X)$$ to be the number of nodes in the subtree rooted at $$X$$. Let the left and right children of $$X$$ be $$X.left$$ and $$X.right$$, respectively. A tree $$T$$ is $$\alpha$$-weight balanced if for every internal node $$X$$ in $$T$$, $$size(X.left) \ge \lfloor \alpha \cdot size(X.right)\rfloor$$ and $$size(X.right) \ge \lfloor \alpha \cdot size(X.left)\rfloor.$$

The height of a BB[$$\alpha$$] tree with $$n$$ nodes is at most $$\log_{1/(1-\alpha)} n=-\log(n)/\log(1-\alpha).$$ Therefore, in order to solve the list-labeling problem, we need $$\alpha = 1 - 1/(1-n^{-1/(\log(m)-1)})$$ to achieve a depth of $$\log(m) - 1.$$

A scapegoat tree is a weight-balanced tree where whenever a node no longer satisfies the weight-balance condition the entire subtree rooted at that node is rebuilt. This rebalancing scheme is ideal for list labeling, since the cost of rebalancing now equals the cost of relabeling. The amortized cost of an insertion or deletion is $$(1+ 1/(1-2\alpha))\log_{1/1-\alpha} n + O(1).$$ For the list labeling problem, the cost becomes:


 * $$ m = n^{\Omega(1)}$$: $$\alpha = O(1)$$, the cost of list labeling is amortized $$O(\log n).$$ (Folklore, modification of Itai, Konheim and Rodeh. )
 * $$ m = O(n) $$: $$\alpha = 1+ \Theta(1/\log n)$$, the cost of list labeling is amortized $$O(\log^2 n).$$ This bound was first achieved by Itai, Konheim, and Rodeh and deamortized by Willard.
 * $$ m = (1+\varepsilon) n $$: If $$m$$ is a power of two, then we can set $$\alpha = 1+ \Theta(\varepsilon/\log n)$$, and the cost of list labeling is $$O(\varepsilon^{-1}\log^2 n)$$. A more careful algorithm can achieve this bound even in the case where $$m$$ is not a power of two.

Lower bounds and open problems
In the case where $$ m = n^{1+\Theta(1)}$$, a lower bound of $$\Omega(\log n)$$ has been established for list labeling. This lower bound applies to randomized algorithms, and so the known bounds for this case are tight.

In the case where $$ m = {(1+\Theta(1))}n$$, there is a lower bound of $$\Omega(\log^2 n)$$ list labeling cost for deterministic algorithms. Furthermore, the same lower bound holds for smooth algorithms, which are those whose only relabeling operation assigns labels evenly in a range of items This lower bound is surprisingly strong in that it applies in the offline cases where all insertions and deletions are known ahead of time.

However, the best lower bound known for the linear case of algorithms that are allowed to be non-smooth and randomized is $$\Omega(\log n)$$. Indeed, it has been an open problem since 1981 to close the gap between the $$O(\log^2 n)$$ upper bound and the $$\Omega(\log n)$$ in the linear case. Some progress on this problem has been made by Bender et al. who give a randomized upper bound of $$O(\log^{1.5} n)$$.

Applications
The best known applications of list labeling are the order-maintenance problem and packed-memory arrays for cache-oblivious data structures. The order-maintenance problem is that of maintaining a data structure on a linked list to answer order queries: given two items in the linked list, which is closer to the front of the list? This problem can be solved directly by polynomial list labeling in $$O(\log n)$$ per insertion and deletion and $$O(1)$$ time per query, by assigning labels that are monotone with the rank in the list. The time for insertions and deletions can be improved to constant time by combining exponential polynomial list labeling with exponential list labeling on small lists.

The packed-memory array is an array of size $$(1+\varepsilon)n$$ to hold $$n$$ items so that any subarray of size $$k$$ holds $$\Theta(k)$$ items. This can be solved directly by the $$m=(1+\varepsilon)n$$ case of list labeling, by using the labels as addresses in the array, as long as the solution guarantees that the space between items is $$O(1)$$. Packed-memory arrays are used in cache-oblivious data structures to store data that must be indexed and scanned. The density bounds guarantee that a scan through the data is asymptotically optimal in the external-memory model for any block transfer size.