What is a linked list?
A linked list is a chain of nodes. Each node holds a value and a pointer to the next node, and the list only remembers where the first node, the head, is. To reach any other node you follow the pointers one by one.
This visualizer shows three kinds. A singly linked list has next pointers only. A doubly linked list also keeps a prev pointer, so you can walk backward. A circular linked list points the last node back to the head, so the chain forms a loop.
Time complexity
| Operation | Time | Notes |
|---|---|---|
| Insert at head | O(1) | Only the head pointer changes |
| Delete at head | O(1) | Head moves to the next node |
| Insert or delete at tail | O(n) | O(1) in the doubly and circular views, which keep a tail pointer |
| Access or search by position | O(n) | No index, so you walk from the head |
Try it yourself
- Insert at head a few times and watch head move.
- Use Search value to see the traversal highlight each node.
- Switch between Singly, Doubly and Circular to compare the pointers.
- Delete at index to see the neighbors re-link around the removed node.
Linked list vs array
A linked list grows and shrinks one node at a time and makes head inserts instant, but it has no index, so reaching the n-th item means walking n steps. An array is the opposite: instant reads, costly inserts in the middle.
Common questions
- What is the difference between singly and doubly linked lists?
- A singly linked list stores one pointer per node (next). A doubly linked list stores two (next and prev), which allows backward traversal and faster deletion of a known node, at the cost of extra memory.
- Why is searching a linked list O(n)?
- There is no index to jump to. You start at the head and follow pointers until you find the value or reach null.
- Where are circular linked lists used?
- They suit round-robin work such as task scheduling or a playlist on repeat, where after the last item you continue with the first.