Data structures

Linked List Operations

A singly linked list visualized as nodes and pointers. Add to the head or tail, remove nodes, and reverse the list in place.

4 minLevel 1/3The interactive stage stays ad-free.
Nodes4Head12Tail78
head
→
12next
→
34next
→
56next
→
78next
→ null

Each box is a node and each arrow is a next pointer. Head insertion is O(1); reaching the tail takes O(n). Reverse relinks every pointer backward in one pass.

What you are seeing

1

Each node stores a value and a pointer to the next node. The list starts at a head pointer.

2

Inserting at the head is O(1); reaching the tail requires walking the list.

3

Reversing changes each next pointer to point backward, then swaps head and tail.

Why it matters

Linked lists teach pointer manipulation and appear in hash-table chains, LRU caches, and memory allocators.

Complexity & details

Insert at head: O(1). Search or delete by value: O(n). Reverse: O(n).

Frequently asked questions

When is a linked list better than an array?+

When you need frequent insertions or deletions at known positions and do not need random access by index.

Why is reversing a linked list a classic interview question?+

It tests pointer bookkeeping: you must save the next node before changing the current pointer, or the rest of the list is lost.