Home

Slidingwindow

Sliding window is a general concept used in computer science to process data in a contiguous window that moves along a sequence. The window is defined by left and right bounds and can be of fixed or variable size. As the window advances, elements enter and leave the window, enabling incremental computation without reprocessing the entire sequence. The approach is commonly implemented with two pointers and supporting data structures such as hash maps to track state.

In algorithm design, the sliding window technique is used to solve problems on arrays or strings efficiently.

Sliding window protocol is a data link layer or transport layer flow control mechanism used in reliable

Practical implementations must handle loss, errors, and timeouts, and may use timers, sequence numbers, and buffering.

Typical
tasks
include
finding
the
maximum
or
minimum
sum
of
a
subarray
of
length
k,
finding
the
longest
substring
that
satisfies
a
property,
or
maintaining
a
count
of
distinct
characters
within
a
moving
window.
Time
complexity
is
often
linear,
O(n),
with
space
complexity
depending
on
the
properties
tracked
inside
the
window.
transmission
over
a
potentially
unreliable
channel.
The
sender
can
transmit
multiple
frames
before
receiving
acknowledgments,
up
to
a
window
size.
As
acknowledgments
arrive,
the
window
slides
forward,
enabling
new
frames
to
be
sent.
Variants
include
stop-and-wait
(window
size
1),
go-back-N
(upon
error,
retransmit
from
the
failed
frame),
and
selective
repeat
(only
erroneous
frames
are
retransmitted).
The
window
ensures
in-order
delivery
and
regulates
the
pace
of
transmission.
The
concept
is
referred
to
as
sliding
window
in
both
software
algorithms
and
networking
contexts,
and
though
related
by
the
idea
of
moving
bounds,
they
address
different
problems:
in-data
processing
versus
reliable
transmission.