LinkedList vs Array
Both type of data structure are used to store linear data of similar types. Though, both have some positive and negative sides.
Advantages of linked list over array:
1. Dynamic Size
As the size of array is fixed, we need to know the upper limit of number of elements in advance. But in practical use, number of elements are less than the upper limit so there is wastage of allocated memory.
2. Ease of Insertion / Deletion
In case of array it is difficult to insert or delete any element in middle of the array as for both insertion and deletion in array, we have to shift other elements to the right or left in the array
Advantages of Array over Linked List:
1. Random access is allowed in array but random access is not allowed in Linked List. We have to access elements sequentially starting from the first node.
2. No extra memory space is required in array as extra space is required for a pointer for each element of the list.
3. Array have better cache locality that can make a pretty big difference in performance.
Advantages of linked list over array:
1. Dynamic Size
As the size of array is fixed, we need to know the upper limit of number of elements in advance. But in practical use, number of elements are less than the upper limit so there is wastage of allocated memory.
2. Ease of Insertion / Deletion
In case of array it is difficult to insert or delete any element in middle of the array as for both insertion and deletion in array, we have to shift other elements to the right or left in the array
Advantages of Array over Linked List:
1. Random access is allowed in array but random access is not allowed in Linked List. We have to access elements sequentially starting from the first node.
2. No extra memory space is required in array as extra space is required for a pointer for each element of the list.
3. Array have better cache locality that can make a pretty big difference in performance.
Comments
Post a Comment