Code

The measuring harness

The tests pass — all your functions are correct. Now we measure them.

Two files in this step, both complete. They are not your task.

graphbench.go — the measuring harness, with two new commands:

command what it does
algo net builds the network and compares BFS with DFS over every reachable destination
algo dense adjacency list against matrix: memory and the cost of a scan

They build the network with buildTrails — the generator from step 3, which makes reading trails rather than random pairs. That matters: a random-pair graph has a completely different shape and this lesson's comparison with transit would not hold.

main.go — two lines, as always: the net and dense commands into usage and into the switch.

First run

Check that the commands work:

$ algo gen -n 1000 -seed 3
$ algo net
$ algo dense

net prints the shape of the network and a table with BFS, DFS and recursive DFS; dense prints the memory of the two representations and the cost of a scan. You will read those numbers in the next steps; for now all that matters is that both run.