Who this book is for
Students ready to explore depth-first search, backtracking, graph reasoning and sorting through Python.
Before you begin
Use functions with return values, loops, lists, dictionaries and grid indices confidently. Python GCSE Advanced or equivalent experience provides the starting skills.
An independent programming resource covering selected A level and extension algorithms. Use your own exam board's specification to identify assessment requirements. The online A level course is still coming soon.
Inside the book
The 12 chapters
- Understand depth-first search
- Follow tree paths and undo choices
- Use DFS to work with binary search trees
- Generate subsets without repeating results
- Build combinations with rules
- Arrange values with permutations
- Explore graphs and find a route
- Find all paths and search word grids
- Check connectivity and detect cycles
- Order tasks with depth-first search
- Partition and sort with quicksort
- Build and test a study planner
Work through explanations and examples, try the independent practice, then use the explained answers to review your reasoning.
Try the approach
Explore a branch before returning
This tiny tree is stored as a dictionary of child lists. Children are visited in the order written.
tree = {'A': ['B', 'C'], 'B': ['D'], 'C': [], 'D': []}
def visit(node):
print(node)
for child in tree[node]:
visit(child)
visit('A')What it prints
A
B
D
CThe search finishes B's branch, including D, before returning to A and visiting C. This example assumes a tree with no cycles; general graphs need additional visited-state handling.
This short public example introduces an idea explored in the book.
