In this post, we will understand the difference between Array and Linked List.
It stores elements in contiguous memory locations.
This means the specific elements can be accessed using easily calculable addresses.
It provides fast access to find element at a specific index.
Size can’t be altered during runtime.
This would overwrite the data.
Memory is allocated to arrays at compile time.
It requires more memory.
Operations like modifying data is quick in array.
Elements are arranged like the following in Arrays −
They are less rigid, elements can be stored in non-contiguous locations.
They require additions values to reference the next element.
Every node in the linked list points to the next element in the linked list.
Since they are non-contiguous, the size of the linked list can be altered at run-time.
Memory is allocated to linked list at run time.
Linked list requires more memory since it includes reference to next node.
Overall, it uses less memory.
Previous elements need to be traversed to reach a specific element.
Operations like insertion or deletion are quick in linked list.
Elements are arranged like the following in LinkedList −