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.

The sidebar follows a suggested learning sequence: foundations and structures, spatial search, graph methods, optional extensions, then integrated applications. You can also follow a shorter route. The concept index supports individual questions. These routes show how the ideas build on one another.

For the course schedule, use the CS2040HS weekly reading map to match each teaching week with the relevant book topics.

RouteRead in this orderWhat connects it
Foundations1. Python objects → 2. Analysis and correctness → 3. Recursion → 4. SortingSpecify behaviour, trace state, prove progress, then count work
Representations and ordered search5. Sequences, stacks, queues and deques → 6. Maps and hashing → 7. Searching and BSTs → 8. AVLCompare the same requested operations under different invariants
Spatial branch7. BST bounds → 8. Balanced trees → 9. Spatial search and indexingCompare point-based cuts, midpoint cells and enclosing object rectangles
Graph algorithms10. Priority queues → 11. Traversal → 12. Union–find → 13. Graph algorithmsQueues, heaps and partitions become algorithm components
Optional design extension14. Strategies, after Topics 1–4; graph examples are useful additional contextGreedy proofs, DP state reuse, backtracking and sequence patterns
Optional strings extension6. Hashing and 7. Tree traversal, then 15. Strings and triesKey length, shared prefixes and reusable pattern information
Integrated transport case11. Traversal, 12. Union–find and 13. Graph algorithms → 16. ApplicationsChoose the objective and weight model before combining structures

Topic 9 follows BSTs and AVL trees to compare spatial invariants with one-dimensional ordering; AVL rotations do not generally preserve k-d-tree partitions. Topics 10–13 establish heaps, traversal and union–find before graph optimisation. Within Topic 13, only Kruskal requires the disjoint-set class. Spatial search is not a prerequisite for the graph route, and Topics 14–15 are optional extensions: the transport case in Topic 16 can be read directly after Topic 13.

Python is the reference for explanations and traces. Every code panel also offers JavaScript and Julia tabs; choose a language with a click or tap. Read the code language guide for indexing, mutation and download conventions.

A common reasoning thread

Each topic asks what the input means, which operations are required, what the representation stores, which invariant remains true, why the procedure finishes, and how work and live storage grow. Use the correctness checklist and cost model across the whole book.

Tie rules and boundary conventions are local contracts. Binary search can use inclusive or half-open intervals if its updates match. BSTs here keep distinct keys; k-d trees send coordinate ties right; priority queues use arrival counters when stable ties are wanted. Follow the stated convention rather than transferring a rule by name alone.

For current scope, conceptual-only coverage and future additions, see Coverage and extensions. Topic 16 now brings these ideas together through a complete fictional transport-network case.

Check your reasoning as you read

All sixteen topics use a self-reading format: two learning goals and prerequisite links at the start of each reading, then a misconception reminder and two prediction questions with expandable explanations. Predict a branch or result before opening the panel; use a mismatch to identify which boundary or invariant to revisit. These are ungraded, original examples.

The spatial sidebar groups k-d trees, point quadtrees, PR quadtrees and R-trees. Compare construction/insertion, exact lookup, range search, nearest search and deletion for each method. The R-tree range helpers precede the exact lookup that reuses them. Compare the cost summaries only after checking which code, occupancy assumptions, node visits and geometry tests each bound describes.

Plan study blocks around the work

Reading a definition, tracing a figure and understanding a complete class require different effort. The blocks below are suggested stopping places, not equal-duration lessons or measured reading-time estimates. Split a block again when you need to draw references, trace code or attempt the checks. Short method/contract pages often orient the longer implementation that follows.

TopicSuggested study blocksMain effort to allow for
1. FoundationsProblems and references; mutation and copies; classes and ADTsDraw shared objects and distinguish slot updates from object updates
2. AnalysisCounts and growth; cases and bounds; code/storage; correctnessDerive a count or invariant before reading its simplified claim
3. RecursionCalls and frames; split/merge trace; costs and allocation choicesFollow returns as well as calls; count live state separately
4. SortingInsertion/bubble; merge; partition/quicksort; runs/comparison/lower boundCompare different invariants using the same sorting contract
5. Linear structuresADT interfaces; arrays/growth; linked edits; queue implementations/choicesTrace empty/singleton transitions and safe link-update order
6. HashingMap/Set contracts; hashing/chaining; probing; rebuilding/choicesFollow a collision chain and tombstones before maintenance costs
7. Searching/BSTsArray search; tree bounds/insertion; traversal/ranges; deletion/public interfaceKeep global bounds and returned subtree roots consistent
8. AVLInvariants/rotations; case identification; updates/operation comparisonDraw transferred subtrees and recompute heights bottom-up
9. Spatial searchShared queries; k-d trees; point quadtrees; PR quadtrees; R-trees; comparisonGive each method its own block; distinguish ownership, enclosure and exact geometry
10. HeapsPriority/shape; repairs; build; records/sorting/costsSeparate complete shape, heap order and application tie policies
11. GraphsModel/representation/updates; BFS; DFS/components; costsTrace frontier and parent state against stored neighbour order
12. Union–findPartitions/forests; weighted union/compression; applicationsTrack membership, representative, element count and component count separately
13. Graph algorithmsTopological order; relaxation/Dijkstra/DAG paths; cuts/Prim/Kruskal; comparisonState the objective before choosing a safe processing order
14. StrategiesStrategy/greedy; DP; backtracking; sequence patterns/limitsGive each new state model its own worked trace
15. StringsString/trie model; trie updates/prefix queries; baseline/KMP; rolling hash/choicesTrace terminal flags, fallback lengths and exact verification separately
16. ApplicationsModel; hop/time routes; connectivity/design; interpretationReuse one dataset while changing the objective and units explicitly

On a first pass, state the contract and trace the supplied example. On a second pass, explain the invariant, implementation choices and full costs, then try the checks without the answers. Revisit prerequisite links when a trace fails; you do not need to restart an entire topic.

Read local contracts with a shared vocabulary

Term or conventionHow to read it across the book
ADT, representation, implementationBehaviour promised to a client; stored organisation/invariant; code that maintains it
Key, value, node, referenceA comparison/lookup field; associated data; a structural object; access to an object. These roles can differ even in one example
Observe versus mutateObserve the logical collection versus change it. Union–find queries may compress representation links while preserving the partition
Remove versus extractRead the named operation’s contract. Stack/queue extraction returns the selected record; Set removal of a specified key may return None or report a Boolean state change
Missing versus stored NoneNone can be legitimate data in several containers. The local contract chooses exceptions, sentinels or absence results
Working versus output storageWorking storage excludes the existing input and returned output when stated separately. This book’s default auxiliary-space convention includes newly allocated output unless explicitly excluded
Height, visits and output sizeHeight bounds a path. A range or spatial query can visit many paths and must pay to report its answers

The brief ADT introduction and analysis conventions define these distinctions. Later pages make their particular result, tie, boundary and error policies explicit.