Linked lists and pointer manipulation
A linked list trades contiguous memory for pointer indirection: each node holds a value and a reference to the next node. Insertion and deletion become O(1) once you hold the right node, but reaching that node costs O(n) because there is no index arithmetic to shortcut the walk.
Most linked-list interview questions are really pointer-ordering questions. The visualizer animates each reassignment so you can see exactly when a link is broken and when it is restored — the moment where reversal bugs and lost tails happen.
Time and space complexity
| Operation | Singly linked | Doubly linked |
|---|---|---|
| Access by position | O(n) | O(n) |
| Search by value | O(n) | O(n) |
| Insert at head | O(1) | O(1) |
| Insert at tail | O(n) without tail pointer | O(1) with tail pointer |
| Delete a known node | O(n) — needs predecessor | O(1) |
How to use this visualizer
Pick an operation such as insertion, deletion, or reversal.
Step through and watch each next pointer get reassigned.
Track the temporary variable that holds the rest of the list during a reversal.
Notice how the head reference moves — losing it is the classic bug.
Frequently asked questions
Walk the list with three references: previous (initially null), current (initially head), and next. On each iteration, save next = current.next, point current.next back at previous, then advance previous = current and current = next. When current becomes null, previous is the new head. It runs in O(n) time and O(1) space.
Use Floyd's tortoise-and-hare: advance a slow pointer one node and a fast pointer two nodes per step. If they ever meet, a cycle exists; if fast reaches null, the list is acyclic. To find the cycle's start, reset one pointer to the head and advance both one step at a time — they meet at the entry node. O(n) time, O(1) space.
A dummy node placed before the real head removes the special case where you insert or delete at position zero. Every operation then has a predecessor to work with, so one code path handles the whole list. It is the standard trick for merge, partition, and remove-nth-from-end problems.