Linked List

A linked list is a data structure where elements (called nodes) are connected using pointers, and each node stores data and a reference to the next node in the sequence.

Fundamental Concepts

Types of Linked Lists

Singly Linked List

A singly linked list is a list where each node contains data and a pointer to the next node, forming a one-way chain.
Key idea: Can move only forward.

10
Head
20
30
Tail
null
Doubly Linked List

A doubly linked list is a list where each node contains data and two pointers — one to the next node and one to the previous node — allowing movement in both directions.
Key idea: Can move forward and backward.

null
10
Head
20
30
Tail
null
Circular Linked List

A circular linked list is a list where the last node points back to the first node, forming a loop instead of ending with null.
Key idea: No end — forms a circle.

10
Head
20
30
Tail

Traversal

10
Head
20
30
40
null

Traversal in a linked list means visiting each node one by one starting from the head and following the pointers until the end, and its time complexity is O(n) because we may need to visit all nodes.

Access

10
Head
20
30
40

Access in a linked list means reaching a specific node by starting from the head and following pointers until the desired position, and its time complexity is O(n) because nodes must be visited sequentially.

Insertion

30
null
10
Head
20

Insertion in a linked list means adding a new node by updating pointers at the desired position, and its time complexity is O(1) if the position is known, or O(n) if traversal is needed to find the position.

Deletion

10
Head
20
30
Tail

Deletion in a linked list means removing a node by updating pointers to skip it, and its time complexity is O(1) if the node is known, or O(n) if traversal is needed to locate it.

Search

10
Head
20
30
40

Search in a linked list means checking each node one by one starting from the head until the target value is found, and its time complexity is O(n) because we may need to examine all nodes.

Time Complexity Comparison

OperationSingly Linked ListDoubly Linked ListCircular Linked ListExplanation
Access (by index)O(n)O(n)O(n)Must traverse
TraversalO(n)O(n)O(n)Visit nodes
SearchO(n)O(n)O(n)Sequential check
Insert at headO(1)O(1)O(1)Pointer update
Insert at tailO(n) / O(1)*O(1)*O(1)*With tail pointer
Delete at headO(1)O(1)O(1)Pointer update
Delete nodeO(n)O(1)**O(n)Need previous node

* O(1) if tail pointer maintained.

** O(1) if node reference available.