Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Dynamic Node-Based Sequences

third = {"value": 30, "next": None}
second = {"value": 20, "next": third}
head = {"value": 10, "next": second}

print(head["value"])
print(head["next"]["value"])

Linked lists store a path from node to node instead of one indexed block

Stacks and queues focused on which item leaves next. Linked lists focus on how items are connected. Each node stores a value and a link to the next node, which makes the structure flexible even though it is less convenient for random access.

Core Explanation

A linked list stores values in nodes. Each node points to the next one.

This makes linked lists conceptually different from Python lists, which store references in an indexed sequence.

Continuity from stacks and queues

Stacks and queues taught processing order. Linked lists now expose the structure underneath many dynamic containers: each element can point to the next one directly.

Exercises

  1. Explain one advantage of linked structures conceptually.

  2. Trace the values in the example node chain.

  3. Compare a linked list to a regular Python list in plain language.

  4. Explain what the None value means at the end of a linked list.

Hint

A linked list is easiest to understand if you picture each node as a small box with two parts: the value and the path to the next box.

Quick Summary
  • linked lists are built from nodes

  • each node stores data and a reference

  • traversal follows next until None

  • linked lists are a useful conceptual bridge to pointer-based structures

Worked Example and Practice Lab

Expected output
A B C

The first example shows the key idea: you do not jump to an index. You follow links one node at a time.

Expected output
['A', 'B', 'C']

Linked-List Building Blocks

These short examples separate the main linked-list ideas into smaller steps.

Create a node chain

Start by linking a few nodes together through the next reference.

Read the head and next node

Follow one next pointer to access the next value in the chain.

Traverse the full list

Move node by node until the chain reaches None. This is the basic linked-list traversal pattern.

Insert a new head node

A new head points to the old head, so insertion at the front is simple.

Guided Practice

What does each linked-list node usually store?

Only the list lengthA node stores more than the overall length.
A value and a reference to the next nodeCorrect. That is the core singly linked-list idea.
Only a dictionary of all nodesThat is not how nodes are usually represented.
A sorted index automaticallyLinked lists do not provide automatic sorting.

What traversal result is printed in the second example?

['C', 'B', 'A']That would be reverse order, not the traversal shown.
['A', 'B', 'C']Correct. Traversal follows `next` from head to tail.
['A']The loop continues through the remaining nodes.
NoneThe loop collects values before reaching `None`.

Key Takeaway

Linked lists make structure explicit: each node knows how to reach the next node. That idea prepares you for more specialized linked forms, including singly and doubly linked lists.