Singly Linked List in Data Structure

Singly Linked List in Data Structure

01 Sep 2025
Beginner
44 Views
12 min read
Learn with an interactive course and practical hands-on labs

Free DSA Online Course with Certification

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.

singly linked list

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.

Data:The Data field stores the actual value of the node.It can be any type of information, such as:Numbers (integers, floats),Characters or strings,Objects or structures.
Next Pointer: The Next field stores the address/reference of the next node in the sequence.It creates the link that connects one node to another.Without the next pointer, the list cannot maintain its sequence.
Null:The last node of a linked list, which points to null, indicating the end of the list. Basic Operations on Singly Linked List

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

We can insert a new node at different positions:
(a) At Beginning
  • 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;
}
(b) At End
  • 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;
}
(c) At Specific Position
  • Traverse to the desired position and adjust pointers accordingly.

3. Deletion

Deleting a node requires adjusting the next pointer of the previous node.
(a) Delete from Beginning
  • 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;
}
(b) Delete from End
  • Traverse to the second-last node, make its next = NULL.
(c) Delete from Specific Position
  • 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: 

OperationDescriptionTime Complexity Space Complexity
Traversal Visit each node in the list O(n)O(1)
InsertionAdd node(beginning, end, position)O(1) / O(n)O(1)
DeletionRemove node (beginning, end, position)O(1) / O(n)O(1)
SearchingFind a node with specific dataO(n)O(1)
Updating Change node’s data valueO(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

1. No Random Access
  • 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

 A Singly Linked List is a linear data structure where each element (called a node) contains data and a pointer (reference) to the next node in the sequence. The last node points to NULL, indicating the end of the list. 

  • 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).

Insertion (at beginning, at end, at a specific position)
Deletion (from beginning, end, or specific position)
Traversal (visiting each node)
Searching (finding a particular value)
Reversing the linked list

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.

GET FREE CHALLENGE

Share Article
About Author
Ankur Mistry (Author, Speaker and Coach)

He has over 12 years of experience in liaising effectively between clients and different team members have been the hallmark. His technical prowess and capability of exploring new frontiers of technology & imparting them to his aspiring team members are his trademark.

He is graduated from South Gujarat University Gujarat-India, working as a Certified Scrum Master and Project Manager with a demonstrated history of working in the information technology and services industry. Skilled in C#, ASP.NET, SQL, ASP.NET MVC, Requirements Analysis, Agile Scrum, DevOps, and Software Project Management, Strong program and project management professional.

His execution is priceless & bringing forth his personal approach will help you realize your dreams, goals, and aspirations into reality.

Live Training - Book Free Demo
ASP.NET Core Certification Training
06 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Advanced Full-Stack .NET Developer with Gen AI Certification Training
06 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI Foundry Certification Training
06 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
React Certification Training
07 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Azure Developer Certification Training
08 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this