275 research outputs found

    Optimal resizable arrays

    Full text link
    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~NN using only O(N)O(N) space, with O(1)O(1) amortized time, or even O(1)O(1) worst-case time, per operation. Sitarski and Brodnik et al.\ describe much better solutions that maintain a resizable array of size~NN using only N+O(N)N+O(\sqrt{N}) space, still with O(1)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 r2r\ge 2, we show that N+O(N1/r)N+O(N^{1/r}) space is sufficient for storing and accessing an array of size~NN, if N+O(N11/r)N+O(N^{1-1/r}) space can be used briefly during grow and shrink operations. Accessing an item by index takes O(1)O(1) worst-case time while grow and shrink operations take O(r)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(N1/r)N+O(N^{1/r}) space to store the array, the amortized cost of grow is Ω(r)\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=2r=2.Comment: To appear in SOSA 202

    Dynamic-array kernels

    Get PDF

    Fast Dynamic Arrays

    Get PDF
    We present a highly optimized implementation of tiered vectors, a data structure for maintaining a sequence of nn elements supporting access in time O(1)O(1) and insertion and deletion in time O(nϵ)O(n^\epsilon) for ϵ>0\epsilon > 0 while using o(n)o(n) extra space. We consider several different implementation optimizations in C++ and compare their performance to that of vector and multiset from the standard library on sequences with up to 10810^8 elements. Our fastest implementation uses much less space than multiset while providing speedups of 40×40\times for access operations compared to multiset and speedups of 10.000×10.000\times compared to vector for insertion and deletion operations while being competitive with both data structures for all other operations

    Efficient Representations for Large Dynamic Sequences in ML

    Get PDF
    International audienceThe use of sequence containers, including stacks, queues, and double-ended queues, is ubiquitous in programming. When the maximal number of elements is not known in advance, containers need to grow dynamically. For this purpose, most ML programs either rely on lists or vectors. These structures are inefficient, both in terms of time and space usage. We investigate the use of chunked-based data structures. Such structures save a lot of memory and may deliver better performance than classic container data structures. We observe a 2x speedup compared with vectors, and up to a 3x speedup compared with lengthy lists

    Almost Wait-free Resizable Hashtables

    Get PDF
    corecore