Definition
Singly Linked List
A singly linked list is a linear data structure consisting of a sequence of nodes, where each node contains:
- Value: The data stored in the node.
- Next: A pointer or reference to the subsequent node in the sequence, or
nullif it is the terminal node (tail).Unlike an array, a linked list does not store elements in contiguous memory locations. Instead, nodes are linked using pointers, allowing for efficient insertions and deletions.
Visual Representation
Complexity
The following table outlines the time complexity of operations on a singly linked list of size :
| Operation | Complexity | Description |
|---|---|---|
| Access | Must traverse from the head to the -th node. | |
| Search | Linear scan for a specific value. | |
| Insertion (at head) | Update the head pointer. | |
| Insertion (at tail) | If a tail pointer is maintained; otherwise . | |
| Deletion (at head) | Move head pointer to the second node. | |
| Deletion (at tail) | Must find the penultimate node to update its next pointer. |
Implementation Details
The head of the list is the entry point for all operations. If the head is null, the list is empty. Singly linked lists are primarily used for implementing other structures like stacks and queues.