diff --git a/posts/algorithms/extrema-circular-buffer.html b/posts/algorithms/extrema-circular-buffer.html index 58ebb74..1250223 100644 --- a/posts/algorithms/extrema-circular-buffer.html +++ b/posts/algorithms/extrema-circular-buffer.html @@ -51,23 +51,19 @@
Design a data structure supporting the following operations:
build(size_t capacity)
+ build(size_t capacity)
: initialize the data structure with capacity/window size
- capacity
+ capacity
capacity
+ capacity
prices.
void push_back(double value)
+ void push_back(double value)
void pop_front()
+ void pop_front()
: remove the price from the front of the window
size_t size()
+ size_t size()
: return the number of prices in the data structure
double get()
+ double get()
: return the extrema (min or max)
std::deque<double>std::deque<double>.
@@ -115,13 +109,13 @@ operations. The minimum/maximum element must be found via a linear scan in \(O(n)\) time, certainly far from optimal.
-
Rather than bear the brunt of the work finding extrema in calls to
- get()get(), we can distribute it across the data structure as it is built.
@@ -214,13 +208,9 @@
std::less<double>
+ std::less<double>
) to easily specify a minimum/maximum
- ExtremaCircularBuffer
+ ExtremaCircularBuffer
as well as a value type to support all operations.