Home
DSA Visualizer
Data Structures
Singly Linked List
Singly Linked List
A singly linked list is a linear collection of data elements in which each element points to the next.
0 / 8 NODES
READY
List is empty
Insert a value to begin. Each node holds a value and a reference to the next one.
At
Value
Intuition
Think of a treasure hunt. Each clue (Node) has a message (Data) and directions to the next clue (Pointer). You must follow them in order; you can't skip ahead or go backwards.
Concept
A Singly Linked List is a sequence of nodes. Each node contains data and a reference (link) to the next node. The last node points to NULL.
How it Works
- Head: The entry point to the list.
- Next Pointer: Stores the address of the next node.
- Traversal: To find an element, you start at Head and follow next pointers.
Step-by-Step Breakdown
- Create a new node with the value.
- Set new node's
nextto current Head. - Update Head to point to the new node.
When to Use
- Dynamic Size: When you don't know the number of elements in advance.
- Frequent Insertions/Deletions: Adding/Removing at the beginning is O(1).
When NOT to Use
- Random Access: Cannot access k-th element directly (O(n)).
- Memory Overhead: Extra memory needed for pointers.
How to Identify
Look for problems involving sequences where you only need to move forward, or when memory efficiency is key (no need for contiguous memory like arrays). Keywords: "Next pointer", "Head/Tail", "Traversal".
Preparing for interviews? This topic is also taught as a pattern:
Linked List Overview
Applying for software engineering roles? Free, no sign-up:
