toy-lib
Safe HaskellNone
LanguageHaskell2010

Algorithm.SlideMin

Description

Sliding minimum window.

Synopsis

Documentation

slideMinIndices :: Int -> Vector Int -> Vector Int #

\(O(N)\) Returns indices of minimum values in the windows with the specified length.

>>> slideMinIndices 3 (U.fromList [0 .. 5])
[0,1,2,3]
>>> slideMinIndices 3 (U.fromList [5, 4 .. 0])
[2,3,4,5]

slideMaxIndices :: Int -> Vector Int -> Vector Int #

\(O(N)\) Returns indices of maximum values in the windows with the specified length.

Example

indices: 0 1 2 3 4 5
values:  0 1 2 3 4 5   max value indices:
         [---]         2
           [---]       3
             [---]     4
               [---]   5
>>> slideMaxIndices 3 (U.fromList [0 .. 5])
[2,3,4,5]
>>> slideMaxIndices 3 (U.fromList [5, 4 .. 0])
[0,1,2,3]

lookBackLowerIndices :: Vector Int -> Vector Int #

\(O(N)\) Solution to the histogram problem. Find the nearest lower building for each i..

lookBackHigherIndices :: Vector Int -> Vector Int #

\(O(N)\) Solution to the histogram problem. Find the nearest higher building for each i..

Example

index:  -1  0   1   2   3   4
height: --  1   5   2   4   3
          <---- |
                | <---- |
                |       | <-|
                | <-|   |   |
          <-|   |   |   |   |
look back: -1  -1   1   1   3

Typical problems