Some of the major advantages and disadvantages of arrays are discussed in this article. Before going into this topic, have a look at these
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.
- Two-dimensional 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 ofthe same data type.
2) Maintains multiple variable names using a single name. Arrays help to maintain large data under a single variable name. This avoid the confusion of using multiple variables.
3) Arrays 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.
4) Arrays can be used for performing matrix operations. Many databases, small and large, consist of one-dimensional and two-dimensional arrays whose elements are records.
5) Arrays can be used for CPU scheduling.
6) Lastly, arrays are also used to implement other data structures like Stacks, Queues, Heaps, Hash tables etc.
You use arrays all the time in programming. Whenever you have to keep track of an ordered list of items, you will end up using an array. Be it a list of songs, a list of books, or list of anything for that matter. Even in the JSON data format, you will often use an array to hold a list of objects.
Databases generally provide a different functionality, as in they let you keep data over time. You can retrieve that data and update it and view it from other computers using other web browsers. You will often retrieve information from a database and store it for local processing in an array. So arrays is an important concept in programming languages.