---
title: "What is the difference between a linked list and an array, and when would you use one over the other"  
description: "What is the difference between a linked list and an array, and when would you use one over the other"  
author: "Revati S Misra"  
published: 2023-04-18  
updated: 2023-04-24  
canonical: https://www.mindstick.com/forum/157903/what-is-the-difference-between-a-linked-list-and-an-array-and-when-would-you-use-one-over-the-other  
category: "data structure"  
tags: ["array", "array list", "data structure"]  
reading_time: 3 minutes  

---

# What is the difference between a linked list and an array, and when would you use one over the other

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between a [linked](https://answers.mindstick.com/qa/104773/how-to-create-a-linked-list) list and an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net), and when would you use one over the other?

## Replies

### Reply by Aryan Kumar

A linked list and an array are both data structures used to store collections of elements. However, there are some key differences between the two.

An array is a collection of elements of the same data type, each identified by an index or a key. The elements are stored in contiguous memory locations, and the index or key is used to access and retrieve the elements. Arrays have a fixed size, and the size must be known at the time of declaration.

On the other hand, a linked list is a collection of nodes, where each node contains an element of data and a reference or pointer to the next node in the list. The nodes are not necessarily stored in contiguous memory locations. Linked lists can grow or shrink dynamically based on the number of nodes they contain.

One advantage of arrays is that they provide constant-time access to elements based on their index or key. This makes them a good choice when you need to access elements frequently and quickly. Arrays are also a good choice when the size of the data is fixed, and there is no need to dynamically resize the array.

On the other hand, linked lists are a good choice when you need to dynamically add or remove elements, as they can grow or shrink themselves to accommodate the new data. Linked lists are especially useful when you need to insert or delete elements frequently from the beginning or middle of the list, as this can be done in constant time.

In summary, arrays are useful for storing data when you need fast and constant-time access to elements based on their index or key, and the size of the data is fixed. Linked lists are useful for storing data when you need to dynamically add or remove elements, and the size of the data may change dynamically or you need to insert or delete elements frequently from the beginning or middle of the list.

### Reply by Krishnapriya Rajeev

A linked list and an array are two different data structures that are used to store and manage a collection of elements.

An **array** is a collection of elements of the *same data type*, which are stored in *contiguous memory locations.* Each element in the array is accessed by its index, which is a non-negative integer that represents its position in the array. Arrays are typically used when you know the size of the collection beforehand and need to access elements randomly.

Arrays are used:

- when you know the size of the collection beforehand and need to access elements randomly.
- Arrays are also more memory-efficient than linked lists since they store elements in contiguous memory locations.

A **linked list** is a collection of nodes, each of which contains an element and a reference to the next node in the list. Unlike arrays, the elements in a linked list are *not stored in contiguous memory locations* and can be accessed only sequentially by traversing the list. Linked lists are typically used when you need to insert or delete elements from the list frequently.

They are used when:

- when you need to insert or delete elements from the list frequently since these operations can be done in constant time.
- Linked lists are also more flexible than arrays since they can grow or shrink dynamically as elements are added or removed.


---

Original Source: https://www.mindstick.com/forum/157903/what-is-the-difference-between-a-linked-list-and-an-array-and-when-would-you-use-one-over-the-other

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
