Linked Lists
Linked List Fundamentals
Master Linked List structures: Singly, Doubly, and Circular Linked Lists, node definitions, and comparison with contiguous array memory.
Last Updated: August 2, 2026
•
15 min read
1. Introduction
What is a Linked List?
A Linked List is a linear data structure where elements are not stored in contiguous memory locations. Instead, each element (called a Node) is a separate object containing a value and a pointer (or reference) that points to the next node in the sequence.Why is it Important?
Unlike arrays, linked lists can grow or shrink dynamically in size without needing expensive re-allocations or element shifts. If you know the reference to the node, inserting or deleting an item takesO(1) time.
Where is it Used?
2. Mental Model: A Scavenger Hunt
Think of a Linked List as a Scavenger Hunt:
head pointer)."Box 1") and a map coordinate pointing to the next clue.null).3. Core Structural Variations
1. Singly Linked List
Each node contains a data value and a single reference pointernext pointing to the subsequent node.
2. Doubly Linked List
Each node contains a data value, anext pointer, and a prev pointer pointing to the preceding node. This allows traversal in both directions but increases memory consumption.
3. Circular Linked List
A list where the final node'snext pointer references the head node rather than pointing to null, creating a closed loop.
Singly Linked List Node Representations
4. Visualizing Variations
Below is a visual representation of Singly, Doubly, and Circular Linked Lists:
5. Real-World Examples
6. Interview Perspective
How Interviewers Ask This Topic
Interviewers test list comparisons:O(1) random access. Linked lists take O(N) lookup.O(N) writes) to insert at the front. Linked lists take O(1) pointer adjustments.Common Mistakes
Warning: 1. Memory Management Leaks in C++: In languages like C++, list node allocations are dynamic. Forgetting to recursively free deleted node structures using
delete will cause severe memory leaks.> 2. Pointer Dereference Crashes: Attempting to readcurr.next.valwhencurrorcurr.nextisnulltriggers immediate runtime crashes (e.g.NullPointerException). Always check bounds.
7. Summary
next reference pointer.next and prev reference pointers.next points back to head.O(N), search is O(N); insertions/deletions at known positions are O(1) time.8. Quiz
Question 1: What is the main advantage of a Linked List over an Array?
Answer: Linked lists have dynamic sizes and can perform insertions/deletions at the head or known positions inO(1) time without needing to shift elements or re-allocate contiguous blocks.
Question 2: What is the time complexity to retrieve the N-th element in a Doubly Linked List?
Answer:O(N) time. Even though we can traverse backwards or forwards, we must still step node-by-node from the head or tail to reach the target index.
Question 3: How does a Doubly Linked List simplify deletions over a Singly Linked List?
Answer: In a Singly Linked List, deleting a node requires finding its preceding node to re-link pointers, takingO(N) scan. In a Doubly Linked List, because each node has a reference to prev, we can delete it in-place in O(1) time directly.
Question 4: True or False: Linked lists are more CPU cache-friendly than arrays.
Answer: False. Arrays are stored in contiguous memory blocks, letting CPU pre-fetchers load sequential indices into cache lines. Linked list nodes are scattered randomly across the heap, leading to frequent cache misses.Question 5: What value does the next pointer of the final node in a Singly Linked List contain?
Answer:null (or nullptr/None), indicating the end of the list.