Documentation for db3f9d3406

This commit is contained in:
realstealthninja
2024-10-28 15:53:44 +00:00
parent fe2cc4c065
commit 4b0a624473
93 changed files with 1589 additions and 328 deletions

View File

@@ -163,7 +163,7 @@ Functions</h2></td></tr>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>An implementation of a median calculation of a sliding window along a data stream. </p>
<p>Given a stream of integers, the algorithm calculates the median of a fixed 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 [find median from (infinite) data stream](<a href="https://www.tutorialcup.com/interview/algorithm/find-median-from-data-stream.htm">https://www.tutorialcup.com/interview/algorithm/find-median-from-data-stream.htm</a>), with the proper modifications to account for the finite window size for which the median is requested</p>
<h3><a class="anchor" id="autotoc_md101"></a>
<h3><a class="anchor" id="autotoc_md102"></a>
Algorithm</h3>
<p>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 from the front of the window is popped. In addition, the algorithm manages a multi-value binary search tree (BST), implemented by <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/multiset.html">std::multiset</a>. For each new value that is inserted into the window, it is also inserted to the BST. When a value is popped from the window, it is also erased from the BST. Both insertion and erasion to/from the BST are O(logN) in time, with N the size of the window. Finally, the algorithm keeps a pointer to the root of the BST, and updates its position whenever values are inserted or erased to/from BST. The root of the tree is the median! Hence, median retrieval is always O(1)</p>
<p>Time complexity: O(logN). Space complexity: O(N). N - size of window </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/YanivHollander" target="_blank">Yaniv Hollander</a> </dd></dl>