A \emph{resizable array} is an array that can \emph{grow} and \emph{shrink} by the addition or removal of items from its end, or both its ends, while still supporting constant-time \emph{access} to each item stored in the array given its \emph{index}. Since the size of an array, i.e., the number of items in it, varies over time, space-efficient maintenance of a resizable array requires dynamic memory management. A standard doubling technique allows the maintenance of an array of size~$N$ using only $O(N)$ space, with $O(1)$ amortized time, or even $O(1)$ worst-case time, per operation. Sitarski and Brodnik et al.\ describe much better solutions that maintain a resizable array of size~$N$ using only $N+O(\sqrt{N})$ space, still with $O(1)$ time per operation. Brodnik et al.\ give a simple proof that this is best possible. We distinguish between the space needed for \emph{storing} a resizable array, and accessing its items, and the \emph{temporary} space that may be needed while growing or shrinking the array. For every integer $r\ge 2$, we show that $N+O(N^{1/r})$ space is sufficient for storing and accessing an array of size~$N$, if $N+O(N^{1-1/r})$ space can be used briefly during grow and shrink operations. Accessing an item by index takes $O(1)$ worst-case time while grow and shrink operations take $O(r)$ amortized time. Using an exact analysis of a \emph{growth game}, we show that for any data structure from a wide class of data structures that uses only $N+O(N^{1/r})$ space to store the array, the amortized cost of grow is $\Omega(r)$, even if only grow and access operations are allowed. The time for grow and shrink operations cannot be made worst-case, unless $r=2$.
翻译:可调整大小数组是一种能够通过在其末尾(或两端)添加或移除元素来实现增长和收缩的数组,同时仍能支持通过索引在常数时间内访问其中存储的每个元素。由于数组的大小(即存储的元素数量)随时间变化,空间高效地维护可调整大小数组需要动态内存管理。标准的倍增技术允许仅用O(N)空间维护大小为N的数组,每次操作具有O(1)均摊时间,甚至可实现O(1)最坏情况时间。Sitarski和Brodnik等人描述了更优的解决方案:仅用N+O(√N)空间维护大小为N的可调整大小数组,且每次操作仍只需O(1)时间。Brodnik等人给出了一个简单证明,表明这是最优结果。我们区分存储和访问可调整大小数组元素所需的空间,以及在数组增长或收缩期间可能需要的临时空间。对于任意整数r≥2,我们证明若在增长和收缩操作期间可短暂使用N+O(N^{1-1/r})空间,则用N+O(N^{1/r})空间就足以存储和访问大小为N的数组。按索引访问元素的最坏情况时间为O(1),而增长和收缩操作的均摊时间为O(r)。通过精确分析一种“增长博弈”,我们证明:对于一大类仅用N+O(N^{1/r})空间存储数组的数据结构,即使只允许增长和访问操作,其增长操作的均摊成本也至少为Ω(r)。除非r=2,否则增长和收缩操作时间无法达到最坏情况常数。