Documentation
¶
Overview ¶
Example 03_advanced_algorithms — runs four algorithms over one shared, immutable CSR snapshot: BFS, Dijkstra, exact Brandes betweenness centrality, and PageRank — and reports per-algorithm evidence.
The example builds a seeded, scale-parametrised synthetic graph with the mutable adjlist builder, freezes it into an immutable CSR snapshot, then runs all four algorithms against that one snapshot. It reports the deterministic results (reachability, two shortest-path distances, the top-k betweenness and PageRank node ids) as bare fact lines, and the volatile cost of each algorithm (wall-clock, PageRank convergence iterations, transient allocations, live heap) as "# "-prefixed telemetry.
Topology — why this generator ¶
The generator was chosen on the advice of the graph-theory-expert sub-agent, so that all four algorithms produce meaningful, distinct, dramatically non-uniform results from one graph:
- Each community is a Barabási–Albert scale-free graph (preferential attachment), which gives a non-uniform PageRank: a few high-degree intra-community hubs dominate the stationary distribution. A near-regular Erdős–Rényi blob would leave PageRank almost flat.
- The communities are joined only through dedicated low-degree bridge nodes wired in a ring. Because a bridge is the sole gateway out of its community, every inter-community shortest path is forced through it, so the bridges are genuine cut vertices whose betweenness towers over every intra-community node. Promoting a hub to also be a bridge would blur that signal, so bridges attach to low-degree members on purpose.
The two mechanisms are orthogonal — preferential attachment shapes within-community mass (PageRank); the bridge ring shapes between-community flow (betweenness) — so they do not fight. A clean teaching consequence is that the bridge nodes have HIGH betweenness but LOW PageRank: the two centrality measures disagree, and the topology shows exactly why.
The graph is built UNDIRECTED. Brandes betweenness is classically read on undirected graphs, and on a connected undirected graph PageRank always converges with no dangling-node sinks. Edge weights are positive with spread and are consumed ONLY by Dijkstra: BFS counts hops, and both Brandes betweenness and PageRank here are the unweighted variants. So Dijkstra's weighted distances generally differ from BFS's hop counts — a deliberate contrast.
Scale ¶
Run with no flags, the example builds a small deterministic default (4 communities of 25 nodes, attachment 2, plus 4 bridge nodes — 104 nodes, ~208 edges) that the regression test pins and that runs in microseconds. Every dimension is a flag, so the same binary scales up to a size where the per-algorithm cost is actually observable:
go run ./examples/03_advanced_algorithms -communities 8 -nodes 500 -ba-attach 3 -seed 7
That is ~4 000 nodes and ~12 000 edges; exact Brandes is O(V*E), so pushing the per-community size into the thousands moves the betweenness pass into seconds. The deterministic facts are reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines.