Optimal resizable arrays
Abstract
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~ using only space, with amortized time, or even worst-case time, per operation. Sitarski and Brodnik et al.\ describe much better solutions that maintain a resizable array of size~ using only space, still with 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 , we show that space is sufficient for storing and accessing an array of size~, if space can be used briefly during grow and shrink operations. Accessing an item by index takes worst-case time while grow and shrink operations take 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 space to store the array, the amortized cost of grow is , even if only grow and access operations are allowed. The time for grow and shrink operations cannot be made worst-case, unless .
Cite
@article{arxiv.2211.11009,
title = {Optimal resizable arrays},
author = {Robert E. Tarjan and Uri Zwick},
journal= {arXiv preprint arXiv:2211.11009},
year = {2023}
}
Comments
Preliminary version appeared in SOSA 2023. Section 6.3 revised