RootishArrayStack: A Space-Efficient Array Stack
Explore the RootishArrayStack data structure and understand its approach to reducing wasted space in array stacks by using blocks of increasing size. Learn how to calculate block indices, perform efficient get, set, add, and remove operations, and manage growth and shrinkage of the structure for optimal space utilization.
We'll cover the following...
Since the data structures that we have studied so far store their data in one or two arrays and avoid resizing these arrays too often, the arrays frequently are not very full. For example, immediately after a resize() operation on an ArrayStack, the backing array is only half full. Even worse, there are times when only one-third of it contains data.
Visual demonstration
A sequence of add(i, x) and remove(i) operations on a RootishArrayStack is illustrated below. Arrows denote elements being copied.
In this lesson, we discuss the RootishArrayStack data structure, that addresses the problem of wasted space. The RootishArrayStack stores elements using arrays. In these arrays, at most array locations are unused at any time. All remaining array locations are used to store data. Therefore, these data structures waste at most space when storing elements.
A RootishArrayStack stores its elements in a list of arrays called blocks that are numbered . See the above slides. Block contains elements. Therefore, all blocks contain a total of
...