|
ADS
Algorithms and Data Structures
|
The order maintenance of exercise 8.11 of Morin (his Sequence), beyond the book: a list of elements with addAfter( e , v ), which adds a new element right after \( e \) (at the front if \( e \) is nil), in \( O( 1 ) \) amortized time, remove( e ), in \( O( 1 ) \) time, and testBefore( a , b ), whether \( a \) comes before \( b \), in \( O( 1 ) \) time. More...
#include "ADS/Contract.h"#include <array>#include <cmath>#include <cstddef>#include <cstdint>#include <utility>#include "ADS/sequence/impl/OrderMaintenanceList.tpp"Go to the source code of this file.
Classes | |
| class | ADS::OrderMaintenanceList< T > |
| a list of items of type T whose order between two elements is tested in \( O( 1 ) \) by labels on two levels More... | |
Namespaces | |
| namespace | ADS |
The order maintenance of exercise 8.11 of Morin (his Sequence), beyond the book: a list of elements with addAfter( e , v ), which adds a new element right after \( e \) (at the front if \( e \) is nil), in \( O( 1 ) \) amortized time, remove( e ), in \( O( 1 ) \) time, and testBefore( a , b ), whether \( a \) comes before \( b \), in \( O( 1 ) \) time.
It is the structure of Bender, Cole, Demaine, Farach-Colton and Zito, a list labeling on two levels (see Sequences by rank and order maintenance):
A split happens once in \( B / 2 \) insertions into a bucket at least, which pay its \( O( B + \log m ) \) labels, since \( \log_2 m < 63 < B \); a removal unlinks its element, and its bucket when it empties, with no relabeling. Hence an insertion costs \( O( 1 ) \) amortized and a removal \( O( 1 ) \) in the worst case. The labels of the buckets hold at most \( ( 2 / T )^{63} \), about \( 5.8 \cdot 10^9 \), buckets. The scapegoat tree whose labels encode the paths, the solution that the exercise has in mind, takes \( O( \log n ) \) amortized (see the theory page). An element stays valid until it is removed.
The contracts [see Contract.h]: the elements given are elements of this list, which holds fewer than \( 5.8 \cdot 10^9 \) buckets; the invariant, checked on the buckets that an operation touches, is that the labels increase, the buckets hold from 1 to \( B \) elements and the elements point to their bucket. The operations are defined in OrderMaintenanceList.tpp.