×
☰ Menu

Introduction 

We have studied that an array is a linear collection of data elements in which the elements are stored in consecutive memory locations. While declaring arrays, we have to specify the size of the array, which will restrict the number of elements that the array can store.

For example,

declare an array as

int arr [10],

then the array can store a maximum of 10 data elements.

But what happens if we don't know ahead of time how many elements there will be? Moreover' to make eminent use of memory, the elements must be stored randomly at any location rather than in consecutive locations. To write effective programs, a data structure that eliminates limitations on the maximum number of elements and the storage condition is therefore required.

 

However, there are a lot of issues with this data structure. Some of the important issues are as follows:

(1) An array is a static data structure and, therefore, its size should be known in advance before its usage.

(2) If a list of data items is to be stored, then an array of approximate size is used, i.e., the array has to be large enough to hold the maximum amount of data one could logically expect. This is totally a guess work and can result in overflow or wastage of main memory.

(3) What if the number of elements in the list is not known in advance?

(4) Insertion or deletion operations in an array, except from the end, are a costly exercise. These operations require large number of shifting of elements in one direction or the other. This a very time-consuming exercise. The above problems can be dealt with the help of linked structures, discussed in the subsequent sections.