How to read a competitive programming pattern or diagram

A diagram in a problem statement is not decoration. It is usually the shortest statement of the structure you are expected to work with: who can reach whom, which states follow which, where the cost sits. Learning to read those drawings takes a few deliberate passes, and it saves far more time than reading the same paragraph four times.

Name every element before you read the text

Start with the legend, if there is one, then identify what the dots, boxes, and lines represent. A dot might be a city, a task, or a state your program can be in. An arrow might mean a one-way street or a legal move. Write the mapping down in your own words: “node equals a prefix sum position; arrow equals a jump of length k”.

Now count what you have. Directed or undirected, weighted or not, labelled with letters or numbers. Those three questions tell you which algorithms could even apply, before you have understood the story.

Check the drawing against the constraints

The figure almost always shows a small case, and small cases lie about scale. Look for the constraint line: how many nodes, how many edges, what values appear on labels. A drawing with six nodes may be describing a graph with a hundred thousand. That difference decides whether you need a traversal or something faster.

  • Does the drawing include a case with duplicates or a self-loop?
  • Are the edges shown as a complete set, or as examples of a pattern?
  • Is there a highlighted path that hints at what the answer looks like?

Redraw it small and by hand

Copy the diagram into your notes with three or four nodes, using the same conventions. Then draw what happens after one step of the obvious process: one move, one relaxation, one split. Watching the picture change is how recurrences and state transitions reveal themselves, and it is much easier on paper than in your head.

If the redraw is confusing, that confusion is information. It usually means you have guessed at the semantics of an edge rather than read them.

Translate the picture into data structures

Once the structure is clear, say out loud how you would store it: an adjacency list for each node’s outgoing edges, a matrix if the drawing is dense and small, an array if the figure is really a line or a grid in disguise. A tree drawn sideways is still a tree; a grid with diagonal moves is a graph in costume.

Look for the picture the problem did not draw

Sometimes the useful diagram is the one you must invent: the dependency order of subproblems, the intervals of a sweep, the layers of a breadth-first search. If a problem feels patternless, sketch your own figure and label the quantities you compute. Many solutions are simply a drawing that made the right ordering obvious.

Read the legend, count the elements, check the constraints, and redraw at a size you can hold in mind. Diagrams reward the reader who treats them as the primary text and the paragraph as the commentary.