【发布时间】:2012-01-18 05:15:22
【问题描述】:
可能重复:
Find the min number in all contiguous subarrays of size l of a array of size n
我有一个(大)数字数据数组(大小 N),并且想要计算一个具有固定窗口大小 w 的运行最大值数组。
更直接地说,我可以为 k >= w-1 定义一个新数组 out[k-w+1] = max{data[k-w+1,...,k]}(这假定数组是从 0 开始的,就像在 C++ 中一样)。
还有比N log(w)更好的方法吗?
[我希望N 中应该有一个线性的,而不依赖于w,就像移动平均线一样,但找不到它。对于N log(w),我认为有一种方法可以使用已排序的数据结构进行管理,该结构将在log(w) 或更少的w 大小的结构上执行insert()、delete() 和extract_max() 或更少——比如以排序二叉树为例]。
非常感谢。
【问题讨论】:
标签: performance algorithm data-structures max