Advantages and disadvantages of arrays in C,C++,Java.

Some of the major advantages and disadvantages of arrays are discussed in this article.

    Advantages of arrays :

  • Arrays represent multiple data items of the same type using a single name.
  • In arrays, the elements can be accessed randomly by using the index number.
  • Arrays allocate memory in contiguous memory locations for all its elements. Hence there is no chance of extra memory being allocated in case of arrays. This avoids memory overflow or shortage of memory in arrays.
  • Using arrays, other data structures like linked lists,stacks,queues,trees, graphs etc can be implemented.
  • 2D arrays are used to represent matrices.

   Disadvantages of arrays :

  • The number of elements to be stored in an array should be known in advance.
  • An array is a static structure (which means the array is of fixed size). Once declared the size of the array cannot be modified. The memory which is allocated to it cannot be increased or decreased.
  • Insertion and deletion are quite difficult in an array as the elements are stored in consecutive memory locations and the shifting operation is costly.
  •  Allocating more memory than the requirement leads to wastage of memory space and less allocation of memory also leads to a problem.
    Applications of arrays :

  1. Array stores data elements of the same data type.
  2. Maintains multiple variable names using a single name. Arrays helps to maintain large data under a single variable name. This avoids the confusion of using multiple variables.
  3. Arrays can be used for CPU scheduling.
  4. It can be used for sorting,data elements. Different sorting techniques like Bubble sort,Insertion sort, Selection sort etc use arrays to store and sort elements easily.
  5. These are used for performing matrix operations. Many databaeses, small and large, consists of 1D and 2D arrays whose elements are records.
  6. These are used to implement other data structures like Stacks,Queues,Heaps,Hashtables etc .
  
Posted on by