From d04cbef12d713073fe81376cb1b4627a642658f0 Mon Sep 17 00:00:00 2001 From: Yaniv Hollander Date: Sun, 3 Oct 2021 21:05:34 -0400 Subject: [PATCH] Update windowed_median.cpp --- probability/windowed_median.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/probability/windowed_median.cpp b/probability/windowed_median.cpp index 11632ed64..d4af73f77 100644 --- a/probability/windowed_median.cpp +++ b/probability/windowed_median.cpp @@ -4,8 +4,8 @@ * * @details * Given a stream of integers, the algorithm calculates the median of a fix size window at the back of the stream. The leading time complexity of this algorithm is - * O(log(N), and it is inspired by the known algorithm to calculate the median of an infinite stream of values, with the proper modifications to account for the finite - * window size for which the median is needed + * O(log(N), and it is inspired by the known algorithm to [find median from (infinite) data stream](https://www.tutorialcup.com/interview/algorithm/find-median-from-data-stream.htm), with the proper modifications to account + * for the finite window size for which the median is requested * * ### Algorithm * The sliding window is managed by a list, which guarantees O(1) for both pushing and popping. Each new value is pushed to the window back, while a value @@ -15,13 +15,11 @@ * whenever values are inserted or erased to/from BST. The root of the tree is the median! Hence, median retrieval is always O(1) * * Time complexity: O(logN). Space complexity: O(N). N - size of window - * @author [Yaniv Hollander] (https://github.com/YanivHollander) + * @author [Yaniv Hollander](https://github.com/YanivHollander) */ -#include -#include -#include -#include -#include +#include // For assert +#include // For std::list - used to manage sliding window +#include // For std::multiset - used to manage multi-value sorted sliding window values /** * @namespace probability