05
SepSingly Linked List in Data Structure
A singly linked list is a linear data structure composed of a sequence of interconnected nodes. Unlike arrays, which have a fixed size and contiguous memory allocation, singly linked lists offer dynamic memory allocation, making them highly flexible for managing data that frequently grows or shrinks.
In this Data structure tutorial, you will explore what is a Singly Linked List, its representation, operations, advantages, disadvantages, and real-world applications to help you understand the concept thoroughly
What is a Singly Linked List?
A singly linked list is a linear data structure consisting of a sequence of nodes, where each node contains two components:
- Data: The value or payload stored in the node.
- Next Pointer: A reference to the next node in the sequence.
Unlike arrays, which store elements contiguously in memory, Singly linked lists use pointers to connect nodes, allowing for dynamic memory allocation. The list has a head (the first node) and ends with a node whose next pointer is null, indicating the end of the list.
Key Characteristics of Singly Linked Lists
- Dynamic Size: The list can grow or shrink as nodes are added or removed, unlike arrays with fixed sizes.
- Unidirectional Traversal: You can only traverse forward (from head to tail) due to the single next pointer.
- Non-Contiguous Memory: Nodes are scattered in memory, linked by pointers, which avoids the need for contiguous memory allocation.
- No Random Access: Unlike arrays, you cannot access elements by index in O(1) time; traversal is required.
- Memory Overhead: Each node requires additional memory for the next pointer.
Representation of Singly Linked List
Each node contains Data and a Next pointer. The Head points to the first node, and each subsequent node points to the next one. The last node points to NULL.
Head:The first node in a linked list is called the head. It is the entry point to the list and used as a reference point to traverse it.
Basic Operations on Singly Linked List
A Singly Linked List (SLL) supports several fundamental operations that allow us to manipulate data efficiently. These operations include traversal, insertion, deletion, searching, and updating.
1. Traversal
Traversal means visiting each node one by one starting from the head until the end of the list (NULL). It is used to display all elements or process data.
void traverse(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
printf("%d → ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
2. Insertion
- Create a new node, point its next to the current head, and make it the new head.
struct Node* insertAtBeginning(struct Node* head, int value) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = value;
newNode->next = head;
return newNode;
}
- Traverse to the last node and update its next pointer to the new node.
void insertAtEnd(struct Node* head, int value) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
struct Node* temp = head;
newNode->data = value;
newNode->next = NULL;
if (head == NULL) {
head = newNode;
return;
}
while (temp->next != NULL)
temp = temp->next;
temp->next = newNode;
}
- Traverse to the desired position and adjust pointers accordingly.
3. Deletion
- Move the head to the next node.
struct Node* deleteBeginning(struct Node* head) {
if (head == NULL) return NULL;
struct Node* temp = head;
head = head->next;
free(temp);
return head;
}
- Traverse to the second-last node, make its next = NULL.
- Traverse to the previous node and adjust its next.
4. Searching
Traverse the list and check if a given key exists.
int search(struct Node* head, int key) {
struct Node* temp = head;
while (temp != NULL) {
if (temp->data == key)
return 1; // Found
temp = temp->next;
}
return 0; // Not found
}
5. Updating
We can modify the value of an existing node without changing its links.
void update(struct Node* head, int oldValue, int newValue) {
struct Node* temp = head;
while (temp != NULL) {
if (temp->data == oldValue) {
temp->data = newValue;
return;
}
temp = temp->next;
}
}
Table of Basic Operations:
Operation | Description | Time Complexity | Space Complexity |
Traversal | Visit each node in the list | O(n) | O(1) |
Insertion | Add node(beginning, end, position) | O(1) / O(n) | O(1) |
Deletion | Remove node (beginning, end, position) | O(1) / O(n) | O(1) |
Searching | Find a node with specific data | O(n) | O(1) |
Updating | Change node’s data value | O(n) | O(1) |
Advantages of Singly Linked Lists
A Singly Linked List (SLL) provides several benefits compared to arrays and other linear data structures:
1. Dynamic Size
- The list can grow or shrink dynamically without requiring memory reallocation.
- Useful when the number of elements is not known in advance.
2. Efficient Insertions/Deletions at Head
- Insertion and deletion at the beginning take O(1) time.
- Arrays require shifting elements, which is O(n).
3. Memory Flexibility
- Uses non-contiguous memory allocation, making it suitable for systems with fragmented memory.
4. Simple Implementation
- Easier to implement compared to doubly linked lists or trees, especially for basic operations.
Disadvantages of Singly Linked Lists
- Elements cannot be accessed directly by index.
- Must traverse from the head to reach the desired element (O(n)).
2. Forward-Only Traversal
- Traversal is possible only in one direction (head to tail).
- Backward traversal requires reversing the list.
3. Memory Overhead
- Each node requires extra memory for storing the next pointer, unlike arrays.
4. Poor Cache Locality
- Since nodes are stored in non-contiguous memory, accessing them is slower compared to arrays.
Real-World Applications of Singly Linked Lists
- Implementing Stacks and Queues: Singly linked lists are used in stack (LIFO) and queue (FIFO) implementations due to efficient head/tail operations.
- Undo Functionality: Software like text editors uses linked lists to store action history for undoing operations.
- Hash Table Chaining: In hash tables, singly linked lists handle collisions by chaining entries in each bucket.
- Operating Systems: Used in task scheduling or memory management for maintaining process lists.
- Music/Video Playlists: Playlists in media players use singly linked lists for sequential playback.
Conclusion
The Singly Linked List is one of the most fundamental data structures in computer science, forming the backbone for more advanced structures like queues, stacks, and graphs. Understanding singly linked lists is crucial for students, developers, and anyone preparing for coding interviews or building a strong foundation in data structures and algorithms (DSA).
Consider enrolling in the best Free Data Structures and Algorithms Certification, to gain comprehensive insights into effective data structure utilization for improved problem-solving and time management.
FAQs
- Arrays have a fixed size, while linked lists are dynamic.
- Arrays provide direct access using an index, whereas linked lists require sequential traversal.
- Insertion and deletion are more efficient in linked lists compared to arrays (except at the end).
Take our Datastructures skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.