Browse curriculum

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

Insert at Head:
  1. Create a new node with the value.
  2. Set new node's next to current Head.
  3. 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:

AI resume checker — match your resume to the job description

Frequently Asked Questions

What is a Singly Linked List?

A Singly Linked List is a linear data structure where each element (node) contains data and a pointer to the next node in the sequence.


Linked List vs Array?

Linked Lists allow for efficient O(1) insertions and deletions (if the pointer is known), whereas Arrays require O(n) shifting. However, Arrays provide O(1) random access.


What is a "Head" node?

The Head is the first node of the Linked List. It serves as the entry point for all operations and traversals.