What are the disadvantages of arrays?a)Data structure like queue or st...
Disadvantages of Arrays
1. Wastage of Memory Space
When elements are inserted in an array and the number of elements is lesser than the allocated size of the array, there is a potential wastage of memory space. This is because the array reserves memory for the maximum number of elements it can hold, even if it is not fully utilized. For example, if an array is allocated to store 100 elements but only 50 elements are actually inserted, the remaining 50 memory locations remain unused, resulting in memory wastage.
2. Fixed Size
Arrays have a fixed size, meaning that the number of elements they can hold is predetermined during their declaration. This can be a disadvantage in situations where the number of elements is not known in advance or can vary dynamically. If the number of elements exceeds the allocated size of the array, it may lead to overflow or data loss. Similarly, if the number of elements is smaller than the allocated size, it results in wasted memory space.
3. Inefficient Insertion and Deletion
Insertion and deletion operations in arrays can be inefficient, especially when performed in the middle or beginning of the array. When an element is inserted or deleted, all the subsequent elements need to be shifted accordingly, which can be time-consuming and result in a high time complexity. This makes arrays less suitable for scenarios where frequent insertion or deletion operations are required.
4. Sequential Access
Elements in an array are stored in contiguous memory locations, which means that accessing elements sequentially is efficient. However, if there is a need to access elements randomly or based on a specific index value, arrays may not be the most suitable data structure. In such cases, other data structures like linked lists or hash tables offer better performance as they allow direct access to specific elements without traversing the entire array.
Conclusion
In conclusion, while arrays have several advantages like fast access to elements and simplicity, they also suffer from certain disadvantages. The potential wastage of memory space when the actual number of elements is lesser than the allocated size is a significant drawback. Additionally, the fixed size of arrays, inefficient insertion and deletion operations, and the sequential access of elements can limit their applicability in certain scenarios.
What are the disadvantages of arrays?a)Data structure like queue or st...
Arrays are of fixed size. If we insert elements less than the allocated size, unoccupied positions can’t be used again. Wastage will occur in memory.
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).