Amortized Rigidness in Dynamic Cartesian Trees

Cartesian trees have found numerous applications due to a peculiar rigid structure whose properties can be exploited in various ways. This rigidness, however, is also an obstacle when updating the structure since it can lead to a very unbalanced shape and so up to now most applications either assumed a random distribution of the keys or considered only the static case. In this paper we present a framework for efficiently maintaining a Cartesian tree under insertions and weak deletions in O(log n) amortized time per operation, using O(n) space. We show that the amortized cost of updating a Cartesian tree is $O(1 + \mathcal{H}(T)/n)$ where $\mathcal{H}(T) = O(nlogn)$ is an entropy-related measure for the partial order encoded by T. We also show how to exploit this property by implementing an algorithm which performs these updates in O(log n) time per operation. No poly-logarithmic update bounds were previously known.