1. Concept library
  2. Data Structures & Algorithms
  3. Module 4: Linked lists

Concept

Singly and doubly linked lists

A linked list is a chain of nodes, each pointing to the next (and in a doubly linked list, the previous). Inserting or removing a node you already hold is O(1), but reaching the nth node is O(n).

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how nodes link and why reaching the nth node is O(n)
  2. Insert and remove a node you already hold in O(1)
  3. Spot the lost tail from overwriting next before saving it

In practice

A few lines that show Singly and doubly linked lists doing its job.

Python
class Node:
    def __init__(self, value, next=None):
        self.value, self.next = value, next

head = Node(1, Node(2, Node(3)))

# insert 9 after the first node, without shifting anything
head.next = Node(9, head.next)

node = head
while node:
    print(node.value)      # 1 9 2 3
    node = node.next

The common mistake

Watch for

Losing the rest of the list by overwriting a next pointer before saving it. When relinking, capture the old next first, then point the node at the new one.

What to know first

Your roadmap puts these before Singly and doubly linked lists, unless you already know them.

How it stays learned

Once a session shows you understand Singly and doubly linked lists, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Singly and doubly linked lists.

Next in the moduleFast and slow pointers →