Module 03 of 12

Linked Lists

Lessons

About This Module

A linked list stores its items as separate nodes, each holding a value and a pointer to the next node. Nothing has to sit side by side in memory, so adding or removing a node is cheap once you are standing next to it, but reaching the 500th item means walking past the first 499. It is the mirror image of the array tradeoff from the last module, and seeing both side by side is the point.

This module starts with what a linked list is and how it is kept in memory, then covers the three common variants: singly, doubly and circular lists, including how to build one and write insert, delete and search. From there it moves to the two classic interview problems: reversing a list, both iteratively and recursively, and detecting a cycle with the fast and slow pointer technique.

Pointer problems are easy to get wrong, so draw the nodes on paper as you watch. Watch the lessons in order, then continue on to Stacks & Queues.

Lessons

4 videos
01

Introduction to Linked List

The starting point: different ways to maintain a list in memory, the types of linked list, and how a single linked list is put together node by node.

02

Linked List Tutorial: Singly + Doubly + Circular

Theory and code in one video for all three types of linked list, including how each one is implemented and why the doubly and circular variants exist.

03

Reverse Linked List: Iterative AND Recursive

NeetCode draws out the pointer changes for LeetCode 206, then codes both the iterative and recursive solutions and compares their memory use.

04

Detect Cycle in Linked List

Covers two approaches, a hash map and Floyd's cycle detection (tortoise and hare), and includes the proof of why the slow and fast pointers must meet.