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

The QUEUE with the minimum of exercise 3.15 of Morin's book, beyond the book [see ADT.h]: enqueue(), dequeue(), top(), size() and min(), all in \( O( 1 ) \) amortized time, on two stacks with the minimum [see MinStack.h]: the items enter the stack \( I \) and leave from the stack \( O \), which, when empty, takes all the items of \( I \) in the reverse order, the front on top. More...

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

Go to the source code of this file.

Classes

class  ADS::MinQueue< T, C >
 a QUEUE with its least item in \( O( 1 ) \) amortized time More...

Namespaces

namespace  ADS

Detailed description

The QUEUE with the minimum of exercise 3.15 of Morin's book, beyond the book [see ADT.h]: enqueue(), dequeue(), top(), size() and min(), all in \( O( 1 ) \) amortized time, on two stacks with the minimum [see MinStack.h]: the items enter the stack \( I \) and leave from the stack \( O \), which, when empty, takes all the items of \( I \) in the reverse order, the front on top.

Each item is pushed and popped twice at most, so that a sequence of \( m \) operations costs \( O( m ) \), and the least item is the lesser of the minima of the two stacks. RealTimeMinQueue [see RealTimeMinQueue.h] spreads the move of the stack \( I \) over the operations, for \( O( 1 ) \) in the worst case.

The contracts [see Contract.h]: top(), dequeue() and min() need a queue that is not empty; enqueue() ensures one item more, dequeue() one less. The operations are defined in MinQueue.tpp.

See also
P. Morin, Open Data Structures (in C++), Edition 0.1G, 2013, https://opendatastructures.org/ods-cpp.pdf, exercise 3.15
R. Hood, R. Melville, Real-time queue operations in pure LISP, Information Processing Letters 13(2), 50-54, 1981, doi:10.1016/0020-0190(81)90030-2 (the queue on two stacks)
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa