Multiple Lists in a Single Array in Data Structure

Data StructureAnalysis of AlgorithmsAlgorithms

Array representation is basically wasteful of space when it is storing data that will change over time. To store some data, we allocate some space which is large enough to store multiple values in an array. Suppose we use the array doubling criteria to increase the size of the array.

Consider the current array size is 8192. This is full. So we need to increase it by using array doubling technique. So new array size will be 16384. Then copy 8192 elements from old array to new array, then deallocate the old array. Now we can realize that before deallocating the space of the old array, the array size is thrice of 8192. The new array with double size and the old array. That is not so good approach.

When we want to store several lists we can share some larger array instead of creating new array for new lists. The multiple list in one array will be look like this −

Though the multiple list in single array is memory efficient, but it has some problem also. Here insertion operation is more expensive. Because it may be necessary to move elements belonging to other lists to insert some element in the current list. And the representation is also harder to implement.

raja
Updated on 11-Aug-2020 07:11:51

Advertisements