AlgoViz

Sliding window (variable size)

medium 20 min

A variable sliding window keeps a contiguous range [left, right] that grows on the right to explore and shrinks on the left whenever a validity rule breaks.

Where it shows up

The same pattern appears across everyday software.

  • Rate limiters

    A sliding-log limiter keeps the timestamps of recent requests and drops those older than the window from the left, then checks whether one more request fits. The window's size changes with traffic, exactly like a variable window over time.

  • Network flow control

    TCP's sliding window lets a sender have a variable number of unacknowledged bytes in flight: the right edge grows as the receiver advertises room, and the left edge moves as acknowledgements arrive.

  • Session and streak analytics

    Finding the longest run of a user's activity with no gap over 30 minutes, or the longest streak of distinct songs played, is a longest-valid-window question over an event stream.

  • Search snippets

    Highlighting the shortest passage of a document that contains all the query words is minimum window substring over the document's tokens.

  • Genomics and log scanning

    Finding the shortest stretch of DNA containing a set of markers, or the shortest slice of logs containing every error code from an incident, uses the same need-and-have counts.