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.
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
Each node stores a value and a pointer to the next node. The list starts at a head pointer.
Inserting at the head is O(1); reaching the tail requires walking the list.
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.