Saturday Questions: Linked Lists in Python
This edition of Saturday Questions is focused on a classic Data Structures and Algorithms topic: linked lists.
Linked lists teach students how data can be connected through references instead of being stored in one continuous block like an array or list. The main idea is simple but powerful: each node stores data and points to the next node.
What you will learn
- Node and next reference
- Linked list traversal
- Insertion at beginning and end
- Deletion from a linked list
- Searching, reversing, and merging
Difficulty path
- Very simple: create and print nodes
- Simple: insert, search, and count
- Medium: delete and reverse
- Interview level: middle node, merge, and cycle detection
Main idea
A linked list is not about storing values only. It is about connecting values carefully.
The basic linked list pattern
Most linked list programs begin with a small node class and a reference to the first node, usually called
head.
class Node:
def __init__(self, data):
self.data = data
self.next = None
head = Node(10)
head.next = Node(20)
head.next.next = Node(30)
current = head
while current is not None:
print(current.data)
current = current.next
next, think carefully about which
node may become unreachable.
Questions included in this edition
- Create a node and print its data
- Create a linked list from a Python list
- Print all elements of a linked list
- Count the number of nodes in a linked list
- Search for a value in a linked list
- Insert a node at the beginning
- Insert a node at the end
- Delete the first occurrence of a value
- Reverse a linked list
- Find the middle node of a linked list
- Merge two sorted linked lists
- Detect a cycle in a linked list
Practice area
Use the embedded practice viewer below. Read each question carefully, try the starter code, then compare your approach with the explanation.
How to attempt the challenge
- First, draw the nodes and arrows on paper.
- Keep track of the
headnode carefully. - Use a
currentvariable for traversal. - Before deleting or reversing, store the next node safely.
- Test empty lists, single-node lists, and multi-node lists.
Why linked lists matter in hiring
Linked list questions are common in coding interviews because they test whether the student understands references, memory-style thinking, and careful step-by-step logic. A linked list problem often looks small, but one careless pointer change can break the entire structure.
Students who become comfortable with linked lists usually become stronger at trees, graphs, recursion, and many other connected data structures.