Node structure
Each node contains a data field and a next field. The final next field stores NULL.
A singly linked list is a sequence of nodes. Each node stores data and a reference to the next node. Nodes do not need to occupy contiguous memory locations.
*O(1) tail insertion is possible when a tail reference is maintained.
Use the controls to modify or inspect the list.
Each node contains a data field and a next field. The final next field stores NULL.
Adding or removing the head changes only the head reference, so both operations take O(1).
There is no direct index access. Reaching a position requires following links from HEAD, which takes O(n) in the worst case.
Reversal changes every next reference so that the former tail becomes the new head. It takes O(n) time and O(1) auxiliary space.
| Operation | Time | Reason |
|---|---|---|
| Add/remove head | O(1) | Only the head reference changes. |
| Access/search | O(n) | Links are followed from HEAD. |
| Add/remove tail | O(n) | A basic singly linked list must find the last or previous node. |
| Insert/delete at known node | O(1) | Only nearby references change. |
| Reverse | O(n) | Every next reference changes once. |
| Bubble Sort | O(n²) | Adjacent values are repeatedly compared. |