Can min/max of moving window achieve in O(N)?

O(N) is possible using Deque data structure. It holds pairs (Value; Index). at every step: if (!Deque.Empty) and (Deque.Head.Index <= CurrentIndex – T) then Deque.ExtractHead; //Head is too old, it is leaving the window while (!Deque.Empty) and (Deque.Tail.Value > CurrentValue) do Deque.ExtractTail; //remove elements that have no chance to become minimum in the window Deque.AddTail(CurrentValue, … Read more

Priority queue in .Net [closed]

You might like IntervalHeap from the C5 Generic Collection Library. To quote the user guide Class IntervalHeap<T> implements interface IPriorityQueue<T> using an interval heap stored as an array of pairs. The FindMin and FindMax operations, and the indexer’s get-accessor, take time O(1). The DeleteMin, DeleteMax, Add and Update operations, and the indexer’s set-accessor, take time … Read more