What Is a Linked List?
A linked list is a linear data structure built from a chain of nodes, where each node holds a piece of data and a reference (a pointer) to the next node. Unlike an array, the elements are not stored in one contiguous block of memory — they can sit anywhere, connected only by those pointers. That single design choice is what gives linked lists their distinctive strengths and weaknesses.
How a Linked List Works
A list keeps a head pointer to its first node. Each node points to the next, and the final node points to nothing (null), marking the end. To find an element you start at the head and follow the pointers one by one. To insert or delete, you simply repoint a couple of references — no shifting of other elements is required, unlike in an array.
Singly vs. Doubly Linked Lists
In a singly linked list, each node points only to the next one, so you can travel in a single direction. In a doubly linked list, each node also points to the previous node, allowing backward traversal and making deletion easier — at the cost of an extra pointer per node. A circular linked list joins the last node back to the head so traversal can loop indefinitely.
Linked List vs. Array
The trade-off is access speed versus modification speed. An array stores elements contiguously, giving O(1) random access by index, but inserting or removing in the middle costs O(n) because everything after must shift. A linked list has no random access — reaching the nth element is O(n) — but once you hold a node, inserting or deleting around it is O(1). Linked lists also grow one node at a time without ever resizing a backing array.
Time Complexity
Searching for or accessing an element by position is O(n) because you must follow the chain. Insertion and deletion are O(1) once you are already at the right node — including at the head, and at the tail too if the list keeps a tail pointer. Memory use is a little higher than an array because every node stores a pointer alongside its data.
Where Linked Lists Are Used
Linked lists are a building block for other structures: stacks and queues are often implemented with them, graph adjacency lists use them, and the chaining buckets inside a hash table are linked lists. They shine when you insert and delete frequently and do not know the size in advance; when you need fast indexed access or cache-friendly iteration, a dynamic array is usually the better fit.
A linked list is a foundational data structure — see how a hash table uses linked lists for its collision chains, compare it with a stack, and see how binary search relies on the random access that linked lists lack.
Frequently Asked Questions
An array stores elements contiguously and offers O(1) access by index, but inserting or deleting in the middle is O(n) because elements shift. A linked list connects nodes with pointers, so insertion and deletion at a known node are O(1), but reaching an element is O(n) because there is no random access.
In a singly linked list each node points only to the next node, so traversal goes one way. In a doubly linked list each node also points to the previous node, enabling backward traversal and easier deletion, at the cost of one extra pointer of memory per node.
Use one when you insert and delete frequently — especially at the ends — and do not need fast random access by index. If you mostly read elements by position or want cache-friendly iteration, a dynamic array is usually the better choice.