Skip to content

9. Worklists and graphs ​

Graph examples require a nested integer sequence for adjacency. This page records grammar from the earlier experimental surface; it is not part of the current callable-Go example set.

Complete program ​

txt
Process the seed values using a first-in, first-out worklist. Admit a value only when it is absent from the discovered values, using linear search. Record each admitted value before adding it to the worklist. After removing each value, append it to a fresh result sequence. Stop processing if that value is equal to the target. Add the neighbors of that value in the adjacency sequences to the worklist in encounter order. Continue until the worklist is empty.

The historical fixture used this input:

json
{"seeds":[0],"adjacency":[[7]],"target":7}

Its recorded result is [0,7]. Download the input.

Context metadata declares sequence<sequence<int64>>; runtime adjacency is a JSON array of integer arrays. FIFO removes from the front; LIFO removes from the back. With the admission clause, discovery is recorded before enqueue, preventing repeated admission in cyclic graphs.

The target check occurs after append and before neighbor expansion. A matched vertex appears in the result, but its adjacency row is not read. Reached invalid rows fail with execution_bounds.

Exercise ​

Use seeds [0], adjacency [[7]], and target 7. Must adjacency contain row 7?

Verified solution

No. The verified result is [0,7]; processing stops before attempting to read row 7.

← State and search · Tabulation →

Stated compiles controlled English deterministically. It does not call an LLM at compile time.