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

The double ended queue with the minimum of exercise 3.16 of Morin's book, beyond the book: push_front(), push_back(), pop_front(), pop_back(), size() and min(), all in \( O( 1 ) \) amortized time, on two stacks with the minimum [see MinStack.h] back to back, as the DualArrayDeque of Morin's book [see DualArrayDeque.h]: \( F \) with the front on top and \( B \) with the back on top. More...

#include "ADS/Contract.h"
#include "ADS/Portable.h"
#include "ADS/stack/MinStack.h"
#include <cstddef>
#include <functional>
#include <utility>
#include <vector>
#include "ADS/queue/impl/MinDeque.tpp"

Go to the source code of this file.

Classes

class  ADS::MinDeque< T, C >
 a double ended queue with its least item in \( O( 1 ) \) amortized time More...

Namespaces

namespace  ADS

Detailed description

The double ended queue with the minimum of exercise 3.16 of Morin's book, beyond the book: push_front(), push_back(), pop_front(), pop_back(), size() and min(), all in \( O( 1 ) \) amortized time, on two stacks with the minimum [see MinStack.h] back to back, as the DualArrayDeque of Morin's book [see DualArrayDeque.h]: \( F \) with the front on top and \( B \) with the back on top.

A removal from an empty side deals the items of the other side again, half to each, the front half to \( F \), in \( O( k ) \) time for \( k \) items; after it each side holds \( \lfloor k / 2 \rfloor \) items at least, so that \( \Omega( k ) \) operations come before another deal, and with the potential \( \Phi = 2 \, | |F| - |B| | \) each operation costs \( O( 1 ) \) amortized. The least item is the lesser of the minima of the two stacks. RealTimeMinDeque [see RealTimeMinDeque.h] spreads the deals over the operations, for \( O( 1 ) \) in the worst case.

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. The operations are defined in MinDeque.tpp.

See also
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