AI engineering glossary · Data structures algorithms
What is sliding window?
Sliding window: A technique that maintains a contiguous range of a sequence and moves it forward one step at a time, updating the answer by adding the new item and removing the old one rather than recomputing. It brings many subarray problems to O(n).
Sliding window: an example
The highest total of any 3 consecutive days of sales in [4, 2, 7, 1, 9] is found by updating a running sum: 13, 10, 17.
Related terms
More Data structures algorithms terms
- Sorting
- Space complexity
- Space-time trade-off
- Stable sort
- String matching
- Tabulation
- Time complexity
- Timsort
Where you learn it
Sliding window is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.