Difference between Array and Linked List

Both Array and Linked List are used to store the data having a similar type, but the difference is that array takes memory locations in contiguous fashion at compile-time, i.e. when we declare of an array, while elements of the linked list take memory, not in contiguous fashion and takes memory at runtime.

Array VS Linked List

  1. An array is a data structure that contains elements of similar data type elements. Whereas the Linked list is a data structure that contains a collection of unordered linked elements known as nodes.
  2. In an array, we can perform random access of the element, but in a linked list we cannot perform the random access, we have to do it sequentially.
  3. In an array, each element has an index number, So that we can access any element by its index number. But in a linked list all elements are connected sequentially, so we have to traverse each element until we find a similar match.
  4. Element access in an array is fast, but in a Linked list, it takes more time, so it is a little bit slower.
  5. Operations like insertion and deletion of an element in arrays take more time as compared to the Linked lists. We can perform this operation in a linked list faster.
  6. The size of an array is fixed, and we cannot increase it at runtime, but the size of the linked list is dynamic we can expand it at runtime as per requirement.
  7. In an array, memory is assigned during the compile time so that size of an array is fixed during the execution of the program while in a Linked list memory is allocated during execution or runtime.
  8. In array memory to the elements of the array is allocated sequentially in the memory whereas in Linked list memory is assigned to the node of linked list is random.
  9. If our requirement of memory is defined or fixed initially, then an array is a better option for our program, but when it is not decided, then a linked list is a better option.
  10. In array memory utilization is inefficient whereas in linked list memory utilization is efficient. 

Array vs Linked list in table

FactorArrayLinked List
StructureFixed-size, contiguous memory allocation.Dynamic-size, non-contiguous memory allocation.
Memory UsageEfficient if size is known in advance.Additional memory for storing pointers.
Access TimeConstant time access (O(1)) for elements.Linear time access (O(n)) required to traverse.
Insertion/DeletionExpensive, especially at the beginning or middle.Efficient, as it involves changing pointers.
ResizingRequires creating a new array and copying elements.No resizing needed; elements can be added/removed dynamically.
Memory AllocationGenerally statically allocated (though dynamic arrays exist).Dynamically allocated.
SearchEfficient for indexed access.Sequential access required, less efficient.
UsagePreferred for static data storage, direct element access.Preferred for dynamic data where insertion/deletion operations are frequent.
Element SizeHomogeneous size (elements are of the same type).Heterogeneous size possible (each node can hold different data types).
Memory WasteNo extra memory apart from the array itself.Extra memory for pointers in each element (node).
Cache-FriendlinessMore cache-friendly due to contiguous memory allocation.Less cache-friendly due to scattered nodes.