Interactive Visualizer

Linked Lists & References

See how nodes connect in memory, add and remove them live, and understand what references really are.

1. Linked List Visualizer

Add a node to get started

2. Memory Layout

Nodes are scattered across memory — not stored contiguously like arrays. Each node holds the address of the next.

3. What's a Reference?

head
variable
0x2A
Node(7)
object in heap memory

A variable doesn't contain an object. It contains a memory address — a pointer to where the object actually lives in heap memory.


When you write head.next = new Node(3), you're saying: "store the address of the new Node object inside head.next."


This is why linked lists work — each node stores the address of the next node, not the node itself. The nodes can live anywhere in memory.

4. The Node Class

// Node definition
class Node {
    int val;
    Node next;

    Node(int val) {
        this.val = val;
        this.next = null;
    }
}

// Usage
Node head = new Node(5);
head.next = new Node(12);
head.next.next = new Node(8);

// Traversal
Node curr = head;
while (curr != null) {
    System.out.println(curr.val);
    curr = curr.next;
}

5. Operations & Complexity

Operation Array Linked List
Access by index O(1) O(n)
Insert at head O(n) O(1)
Delete at head O(n) O(1)
Insert at end O(1)* O(n)
Search O(n) O(n)
Memory Contiguous Scattered

* Amortized O(1) for dynamic arrays

6. Where Linked Lists Are Used

LRU Cache
Doubly linked list + hashmap. O(1) access and eviction of least recently used items.
Undo / Redo
Each state is a node. Navigate backward (undo) and forward (redo) through history.
Music Playlists
Skip to next/previous track. Easy reorder without shifting all elements.
File Systems
File blocks linked together on disk. Blocks don't need to be contiguous.