Skip to main content
All Data Structures courses

Singly Linked List

Learn in-depth the most fundamental data structure in a programmer's life

32 Lessons
48 problems
7 Patterns
158 Illustrations
112 Slides

What you will learn

How linked lists scatter nodes across memory and trade random access for O(1) head insertion

The reversal pattern in both forms: direct list reversal and reversal as a subproblem

Sliding window traversal using two references kept a fixed distance apart

Fast and slow pointers for middle node search, cycle detection, and palindrome checks

Split, merge, and reorder using dummy heads and parallel tail references

How Floyd's tortoise and hare algorithm finds a cycle in O(N) time and O(1) space

Why this course

A linked list is a node holding a value and a pointer to its neighbour. Defining it takes one sentence. Reversing one without losing the rest of the list, finding the middle in a single pass, or merging two sorted chains in place is choreography: three references moving in the right order, any slip erasing half the list. The trouble is rarely the structure. It is the pointer hygiene.

This course rebuilds singly linked lists from the single-node primitive up, then walks through the seven pointer manipulation patterns that cover almost every linked list question you will see in a coding interview. You finish by implementing a singly linked list of your own with every supported operation working at its tightest complexity.

Requirements

The course assumes you can read code in any mainstream language and have written a function or two that mutates an object through a reference.

  • Comfort writing loops, conditionals, and small functions in at least one language.
  • A working idea of references or pointers (passing an object into a function and mutating it from inside).
  • Basic Big-O notation literacy: O(N), O(1), O(log N).

Overview

A singly linked list is the data structure that motivates every other pointer-based structure in computer science. Stacks, queues, hash table chains, trees, graphs, and adjacency lists all sit on the same primitive: a node with a value and a reference to its neighbour. It is also where most engineers first meet the cost of indirection. Walking an array of one million integers stays in cache; walking a linked list of one million nodes touches one million scattered addresses, which is why production systems often prefer arrays even when textbook complexity favours a list.

Representation of a singly linked list

The course teaches both halves of the topic: how the structure works at the pointer level, and how to recognise which of the seven patterns a given problem fits into.

Fundamentals

The course opens with the node, the primitive every linked list operation manipulates. You see how each node packages a data field with a next reference, how a head pointer anchors the chain, and how the tail node's null next is the stop signal traversal listens for. From there the cost of every supported operation follows directly: access by index is O(N) because you have to walk from the head, head insertion is O(1) because no shifting is needed, and tail insertion without a tail reference is O(N) because you have to find the end first.

Insertion and deletion are then taught as a family rather than as a list of recipes to memorise. You see five insertion variants (at the head, at the tail, after a given node, before a given node, at distance X) and seven deletion variants (first node, last node, by value, after a node, before a node, by node reference, at distance X), and how each variant decomposes into the same two-or-three pointer rewires once you know which neighbour reference you are missing.

The fundamentals close with Floyd's tortoise and hare algorithm. You walk through why two pointers moving at different speeds detect a cycle in O(N) time and O(1) space, then extend the same idea to find the cycle's entry node. This sets up a recurring theme of the rest of the course: most non-trivial singly linked list problems are solved by running two references over the list at the same time, in different ways.

Problem solving

After the fundamentals, the rest of the course is patterns. Most linked list problems you see in an interview reduce to one of seven templates, and once you can recognise the template the pointer wiring becomes the only hard part.

The 7 singly linked list patterns you'll master
Reversal
A three-pointer walk with previous, current, and next references that reverses the whole list or a segment of it in place in O(N) time and O(1) space. Reverse a List, Reverse First K Nodes, Reverse Last K Nodes, Reverse the Given Segment.
Reversal as a subproblem
Decompose a harder problem into repeated segment reversals chained together with a dummy head and a connector reference, the building block underneath the medium and hard list problems. Pairwise Swap, Reverse K Segments, Reverse Increasing Groups, Reverse Alternate Segments.
Sliding window traversal
Two references kept exactly K nodes apart and advanced together, solving Nth-from-end problems in a single pass with O(1) auxiliary space. K Maximum Sum, Trim Nth Node, Swap Nth Nodes, K Rotations.
Fast and slow pointers
Two references moving at different speeds to land on a proportional position in one pass, the same mechanic Floyd's cycle detection uses. Middle Node Search, Split List in Half, Equal Halves, Palindrome Checker.
Split
Distribute nodes into K separate output lists in a single pass using parallel dummy heads and per-list tail references, running in O(N) time and O(1) auxiliary space. Even Odd Split, Split Alternate Groups, Split By Modulo, K Way List Split.
Merge
Combine two or more lists into one by choosing the next node via a selector function, using a dummy head and a tail reference, in O(N + M) time. Alternate Node Fusion, Merge Sorted Lists, Merge Sorted Lists II, List Addition.
Reorder
Compose a split on one function with a merge on another to rearrange nodes in place, the most general singly linked list pattern. Relocate Node, Parity Order, Value Partition, Shuffle List.

Each pattern is taught in three layers. An Understanding lesson walks through the technique on a problem where the pattern is obvious. An Identifying lesson teaches you the signals that tell you a new problem fits the template, the same triggers an experienced engineer reads in an interview. Then four problems give you progressively harder applications. The course closes with a design capstone where you implement a singly linked list of your own, with every supported operation written at its tightest complexity and tested against an array-backed reference implementation.

How this course is different

Most linked list resources stop at reversal and cycle detection, treating each subsequent problem as its own one-off trick. This course teaches the seven patterns underneath, so you recognise the template before you write a single pointer assignment.

Most DSA resources
This course
✗Treat linked lists as a one-page topic before jumping straight to "100 linked list problems".
✓Opens with the node primitive and builds every operation from explicit pointer rewires.
✗Teach reversal as a single trick, leaving you unable to apply it to pairwise swap or K-segment reversal.
✓Treats reversal as two distinct patterns (direct reversal and reversal as a subproblem) so you can apply it to harder problems.
✗Cover Floyd's cycle detection in isolation, missing that the same two-speed idea solves middle node and palindrome.
✓Groups middle node, palindrome checking, and cycle detection under one fast-and-slow-pointers family.
✗Skip the dummy head and tail reference idiom, so merge and split solutions become tangled with edge cases.
✓Teaches the dummy head with tail reference idiom as the unifying device behind split, merge, and reorder.
✗Stop at the algorithm and never have you implement a singly linked list yourself.
✓Ends with a design capstone where you implement the data structure your standard library hides from you.

Who this course is for

The course suits anyone who has heard the words "linked list" but is not yet confident they could wire one up cleanly under interview pressure.

  • New programmers who can write a for loop but have never traced what node = node.next does to the reference under the variable.
  • Self-taught and bootcamp graduates who solved a few linked list problems on LeetCode but cannot recognise the patterns underneath.
  • Working developers who use ArrayList and HashMap every day and have not written a node-based structure since school.
  • Engineers preparing for FAANG and Big Tech interviews where reversal, cycle detection, and merge questions appear in nearly every onsite.
  • Returning engineers who learned linked lists years ago and want a refresher that goes past the textbook reversal walkthrough.
  • Anyone who can sketch a linked list on a whiteboard but loses the thread when asked to swap two adjacent nodes correctly.

Continue your DSA journey

Linked lists are the gateway data structure for every other pointer-based topic in this curriculum. After this course, your next step depends on whether you want to deepen pointer skills or move into structures that sit on top of linked lists.

  • Array: The contrast course. Arrays and linked lists are the two ways to lay out a sequential collection in memory: contiguous bytes versus pointer-chased nodes. Understanding both is how you can defend your data structure choice in a system design interview.
  • Doubly linked list: The natural continuation. Adding a previous pointer makes several patterns simpler and unlocks new ones (LRU cache, deque, in-place reorder). The pointer hygiene you built here transfers directly, so most learners take this course right after.
  • Stack: A stack backed by a linked list pushes and pops at the head, the same O(1) operation you learned in the insertion lessons. The stack course also uses traversal patterns as a setup for the previous-closest and next-closest families.
  • Queue: A queue is the canonical application of a singly linked list with both head and tail references. Once you have those two pointers, enqueue and dequeue both become O(1) operations, and the standard library queue stops looking like magic.
  • Graph: Adjacency lists, the standard representation for graphs, are arrays of singly linked lists. The traversal habits and pointer hygiene you build here are the same toolkit that powers BFS, DFS, and shortest path on a graph.
  • Recursion: A singly linked list is itself a recursive data structure (a node is either null or a value followed by a smaller linked list). The recursion course teaches the head, tail, and multiple recursion shapes that come up when you solve list problems recursively rather than iteratively.

Frequently asked questions