Difference Between Array and Linked List


The basic difference between an array and a linked list is in their structure. An array relies on the index-based data structure, whereas a liked list is based on the references. Read this article to find out more about Arrays and Linked Lists and how they are different from each other.

What is an Array?

An array is a consistent set of fixed number of data items. Array stores elements in contiguous memory locations. This means the specific elements can be accessed using easily calculable addresses. Hence, an array provides fast access to find element at a specific index.

Another important characteristics of array is that its size cannot be altered during runtime. Memory is allocated to arrays at compile time. Arrays require less memory, however operations like insertion, deletion, etc. take a longer time in an array.

What is a Linked List?

A linked list is an ordered set of a variable number of data items. Linked lists are less rigid, because elements are stored in non-contiguous locations. Also, they require additions values to reference the next element. Hence, 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 a linked list at runtime. A linked list requires more memory as compared to an array because it includes references to the next node. Operations like insertion or deletion are quick in a linked list.

Now, let us discuss the differences between array and linked list in detail.

Difference between Array and Linked List

The following table highlights all the major differences between array and linked list −

S.No.

Array

Linked List

1.

An array is a consistent set of fixed number of data items.

A linked list is an ordered set of a variable number of data items.

2.

They are stored in contiguous memory locations.

They are not stored in contiguous memory locations.

3.

In the case of arrays, the memory allocation is done at compile time.

In the liked lists, memory allocation is done at run time.

4.

Arrays are fixed in size.

Linked lists are dynamic in size.

5.

Arrays require less memory space as compared to linked lists.

Linked lists require more memory space.

6.

In the case of arrays, the insertion and deletion operations require more time to execute.

In the linked lists, the insertion and deletion operations take less time.

7.

In arrays, accessing the elements is easier.

In linked lists, the whole linked list is to be traversed to access the elements.

Conclusion

The most significant difference that you should note here is that an array stores elements in contiguous memory locations, while a linked list stores elements in non-contiguous locations.

Updated on: 20-Feb-2023

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements