Linked List vs Array (original) (raw)

Last Updated : 1 Jun, 2026

Arrays and Linked Lists are two of the most commonly used linear data structures for storing collections of data. Although both are used to store multiple elements, they differ in memory allocation, access methods, and performance characteristics.

Array

An Arrays is a linear data structure that stores elements of the same data type in contiguous memory locations. Since the memory addresses are sequential, any element can be accessed directly using its index.

Data storage scheme of an array

C++ `

#include using namespace std;

int main() { int arr[] = {10, 20, 30, 40, 50};

cout << arr[2];

return 0;

}

`

**Explanation: The element at index 2 is accessed directly from the array, so the value 30 is printed in O(1) time.

Linked List

Linked list is a linear data structure consisting of nodes, where each node contains data and a reference to the next node. Unlike arrays, nodes are not stored in contiguous memory locations.

Linked-List representation

C++ `

#include using namespace std;

class Node { public: int data; Node* next;

Node(int value) {
    data = value;
    next = NULL;
}

};

int main() { Node* first = new Node(10); Node* second = new Node(20);

first->next = second;

cout << first->data << endl;
cout << first->next->data;

return 0;

}

`

**Explanation: The first node stores 10 and points to the second node storing 20, creating a simple linked list with two nodes.

Array Vs Linked List

Feature Array Linked List
Memory Storage Elements are stored in contiguous memory locations. Nodes are stored in non-contiguous memory locations.
Access Time Direct access using index in O(1) time. Sequential access requiring O(n) time.
Insertion Insertion is slower due to element shifting. Insertion is faster as only pointers are updated.
Deletion Deletion requires shifting remaining elements. Deletion is efficient with pointer adjustments.
Size Generally fixed after creation. Can grow or shrink dynamically.
Memory Usage Requires less memory overhead. Requires extra memory for pointers.
Cache Performance Better cache locality and faster traversal. Poor cache locality due to scattered nodes.
Implementation Simple and easy to implement. More complex because of pointer management.
Searching Faster when index is known. Requires traversal from the beginning.
Best Use Case Suitable for frequent access operations. Suitable for frequent insertion and deletion operations.

**Advantages of Linked List over arrays

**Advantages of Arrays over Linked List