ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RealTimeMinDeque.h File Reference

The double ended queue with the minimum of exercise 3.16 of Morin's book in \( O( 1 ) \) worst-case time per operation, beyond the book [see MinDeque.h for the amortized one]: push_front(), push_back(), pop_front(), pop_back(), front(), back(), size() and min(), by the global rebuilding of Overmars applied to the two stacks of MinDeque, as Gajewska and Tarjan do for the deques with heap order. More...

#include "ADS/Contract.h"
#include "ADS/Portable.h"
#include "ADS/queue/RealTimeMinQueue.h"
#include <algorithm>
#include <array>
#include <concepts>
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <utility>
#include "ADS/queue/impl/RealTimeMinDeque.tpp"

Go to the source code of this file.

Classes

class  ADS::RealTimeMinDeque< T, C >
 a double ended queue with its least item, every operation in \( O( 1 ) \) worst-case time More...

Namespaces

namespace  ADS

Detailed description

The double ended queue with the minimum of exercise 3.16 of Morin's book in \( O( 1 ) \) worst-case time per operation, beyond the book [see MinDeque.h for the amortized one]: push_front(), push_back(), pop_front(), pop_back(), front(), back(), size() and min(), by the global rebuilding of Overmars applied to the two stacks of MinDeque, as Gajewska and Tarjan do for the deques with heap order.

The items are on two stacks back to back, \( F \) with the front on top and \( B \) with the back on top, arrays whose cells hold the place of the least item at or below them. When one side \( G \) has more than \( 3 m + 1 \) items, \( m \) those of the other side \( S \), or a side fills half its array, a rebuild starts: of the \( n_0 \) items, the \( \lceil n_0 / 2 \rceil \) nearest the top of \( G \) will stay on its side and the \( t \) at its bottom will pass to the other, and two new arrays of \( 2 n_0 + 16 \) cells are filled from the bottom with copies, twelve per operation: \( S' \) with the bottom of \( G \) from \( G[ t - 1 ] \) down to \( G[ 0 ] \) and then the items of \( S \) from its bottom, \( G' \) with \( G[ t ] , G[ t + 1 ] , \ldots \). The operations go on on the old stacks meanwhile, and a copy keeps a prefix of its stack, shortened by one when a removal goes below its end; the rebuild ends when both prefixes reach their tops, and the new arrays replace the old ones, which are destroyed twelve cells per operation afterwards. A deque of fewer than 32 items is rebuilt at once, in \( O( 1 ) \). A rebuild takes fewer than \( n_0 / 11 + 2 \) operations, during which neither side of the old stacks empties nor goes below the cells being copied, so that the minimum is the lesser of the minima of the two old stacks; the next rebuild comes \( \Omega( n_0 ) \) operations later, after the old arrays are gone. See The minimum in constant worst-case time. The items are copied, so that T must be copyable.

The contracts [see Contract.h]: the removals, front(), back() and min() need a deque that is not empty; the insertions ensure one item more and the removals one less; a rebuild never reads a cell that a removal has destroyed (an invariant). The operations are defined in RealTimeMinDeque.tpp.

See also
H. Gajewska, R. E. Tarjan, Deques with heap order, Information Processing Letters 22(4), 197-200, 1986, doi:10.1016/0020-0190(86)90028-1
M. H. Overmars, The Design of Dynamic Data Structures, Lecture Notes in Computer Science 156, Springer, 1983, doi:10.1007/BFb0014927 (the global rebuilding)
P. Morin, Open Data Structures (in C++), Edition 0.1G, 2013, https://opendatastructures.org/ods-cpp.pdf, exercise 3.16
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa