Chapter 24 · Graph Algorithms: Centrality, Community Detection, Similarity, Paths, and Topology Analytics

Choose an Algorithm from the Decision Question, Validate Assumptions, and Interpret Results Without Overclaiming

Choose GDS algorithms from decision questions, validate assumptions with fixtures/baselines/sensitivity evidence, and create a reproducible interpretation/runbook before moving to graph ML.

Advanced240–350 minutesAlgorithm selection · validationNeo4j 2026.07.1 · Community mandatoryGDS Community 2026.07.0 · Cypher 25Algorithms · estimates · stream first · concurrency ≤4 CEJava 21/25 · GDS plugin requiredLast reviewed: September 2026

Learning outcomes

01

Map a decision question to a graph algorithm family and reject algorithms whose assumptions do not match the data.

02

Build an evidence card covering projection, orientation, weights, parameters, memory, concurrency, mode, baseline, and interpretation limits.

03

Validate centrality, communities, similarity, and paths with hand fixtures or simple baselines before scaling.

04

Test sensitivity/stability and distinguish exploratory analytics from production decision support.

05

Produce a reproducible Chapter 24 runbook and cleanly bridge into graph embeddings and ML pipelines.

Execution and safety note

Treat every command, query, configuration change, benchmark, security change, failure injection, and cleanup step in this lesson as scoped to the disposable AtlasMart course lab unless the text explicitly says otherwise. Verify the actual Neo4j, Cypher, driver, plugin/GDS, edition/tier, authentication, TLS, and deployment state before execution. Expected results describe invariants and evidence shapes; they are not fabricated claims that this generated lesson captured a live production run.

1. AtlasMart problem: an algorithm portfolio can become a cargo-cult portfolio

After four lessons, AtlasMart can run dozens of GDS algorithms. That capability creates a new risk: selecting the algorithm whose name sounds impressive, then fitting a business story to the score. Production analytics must reverse that sequence. Begin with a decision and a falsifiable structural hypothesis; then select the minimal algorithm family that tests it.

Dimension Chapter 24 reproducible assumption
Neo4j 2026.07.1 Community, disposable local/container deployment; database neo4j.
Cypher Cypher 25 for course examples; Cypher 5 differences are not needed for the GDS procedures used here.
Java Java 21/25 supported by the 2026 line; container image supplies the runtime.
Auth/TLS User neo4j, password atlasmart-course-2026; loopback Bolt without TLS only for this isolated lab.
Driver No application driver is required for mandatory GDS procedure labs; cypher-shell/Browser is sufficient.
GDS GDS Community 2026.07.0. Community includes all algorithms; maximum GDS concurrency is four CPU cores.
APOC Not required.
Graph scope Only identifiers prefixed CH24- plus named in-memory projections beginning atlas-ch24- are created.
Runtime evidence This artifact does not execute Neo4j/GDS. Exact fixture counts and hand calculations are deterministic; timings, memory estimates, and algorithm scores must be measured locally.
Verify the Chapter 24 lab baseline
// Run in the disposable atlasmart-gds lab from Chapter 23.
RETURN gds.version() AS gdsVersion;
CALL dbms.components() YIELD name, versions, edition
RETURN name, versions, edition;

// Defensive cleanup of Chapter 24 projections if rerunning.
CALL gds.graph.list()
YIELD graphName
WITH graphName WHERE graphName STARTS WITH 'atlas-ch24-'
CALL gds.graph.drop(graphName) YIELD graphName AS dropped
RETURN dropped;

2. The decision-question matrix

Decision question Candidate algorithm Key assumptions to validate Minimum baseline
Which nodes have many direct ties? Degree Edge direction/type and optional weights mean direct exposure/connection. Cypher COUNT of intended relationships.
Which nodes receive transitive influence? PageRank / Eigenvector Direction and iterative influence model match the process; damping for PageRank justified. Degree + simple known graph.
Which nodes bridge shortest routes? Betweenness Shortest-path metric represents flow; exact vs sampled choice justified. Hand shortest paths on tiny fixture.
Which nodes form dense structural groups? Louvain / Leiden / LPA Projection has community structure; weights/resolution/seed semantics valid. Known two-block fixture + partition-stability check.
Which nodes share neighbors? Node Similarity Bipartite/outgoing-neighborhood model is meaningful. Manual Jaccard/Overlap pairs.
Which nodes are near in property space? KNN Projected properties and metric represent similarity; approximation evaluated. Exact small-set neighbor calculation.
What is the cheapest/reachable route? Dijkstra / BFS / DFS / spanning family Cost and termination semantics valid; projection fresh enough. Manual route/reachability fixture.

3. Algorithm evidence card: required before a production interpretation

Example evidence-card YAML
decision_question: "Which catalog products act as structural bridges between co-interest groups?"
source_cutoff: "<record timestamp/CDC checkpoint>"
neo4j: "2026.07.1"
gds: "2026.07.0 Community"
projection:
  name: "atlas-ch24-centrality"
  node_labels: [Product]
  relationship_types: [RELATED_TO]
  orientation: NATURAL
  node_count: "<measure>"
  relationship_count: "<measure>"
  degree_distribution: "<record p50/p95/p99/max>"
algorithm:
  name: "gds.betweenness.stream"
  mode: stream
  relationship_weight_property: null
  sampling_size: "<node count for exact, or justified sample>"
  sampling_seed: "<set when sampling>"
  concurrency: 2
resource_evidence:
  estimate_required_memory: "<measure>"
  compute_millis: "<measure>"
validation:
  hand_fixture: "passed"
  baseline: "degree ranking recorded"
  sensitivity: "sampling/direction changes recorded"
interpretation_limit:
  - "structural brokerage only"
  - "not causal"
  - "not profit/value"
refresh_and_rollback:
  cadence: "<define>"
  projection_drop: "CALL gds.graph.drop(...)"
  persistent_write: false

4. One end-to-end bounded Chapter 24 validation run

The following is a runbook skeleton, not fabricated output. It deliberately separates deterministic checks from measurements you must capture locally.

Runbook: estimate → stream → baseline → interpret
// 1. Verify exact versions.
RETURN gds.version() AS gdsVersion;

// 2. Inspect projection evidence.
CALL gds.graph.list('atlas-ch24-centrality')
YIELD graphName, nodeCount, relationshipCount, schemaWithOrientation, degreeDistribution
RETURN *;

// 3. Estimate chosen algorithm before running.
CALL gds.betweenness.stream.estimate('atlas-ch24-centrality', {concurrency:2})
YIELD requiredMemory, bytesMin, bytesMax
RETURN *;

// 4. Run in stream mode first: no persistent side effect.
CALL gds.betweenness.stream('atlas-ch24-centrality', {concurrency:2})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).productId AS productId, score
ORDER BY score DESC, productId;

// 5. Compare with simple degree baseline.
CALL gds.degree.stream('atlas-ch24-centrality')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).productId AS productId, score
ORDER BY score DESC, productId;

// 6. Drop the in-memory artifact when the run is complete.
CALL gds.graph.drop('atlas-ch24-centrality') YIELD graphName
RETURN graphName;

5. Sensitivity is part of correctness for heuristic/approximate analytics

Family Sensitivity experiment What instability means
PageRank Vary damping/weights/direction within justified ranges. Ranking depends on model assumptions; do not present as intrinsic node truth.
Betweenness Compare exact tiny graph vs sampled larger graph; vary samplingSeed/sample size. Approximation uncertainty can reorder candidates.
Leiden Repeat across randomSeed and justified gamma/theta values. Partition is not stable enough to become a governed business segment without more evidence.
Louvain/LPA Vary weight use, projection, refresh data, iteration/tolerance/seedProperty where supported. Partition sensitivity may dominate any business interpretation.
KNN Compare approximate top-k with exact small-set neighbors; vary seed/metric. Candidate recall may be insufficient.
Paths Vary cost definition and direction; validate ties and unreachable cases. Operational answer is driven by cost model/topology, not just algorithm implementation.

6. Deliberately wrong: compare raw algorithm scores across unrelated graphs

A PageRank score from a six-node product projection and a PageRank score from a million-node supplier graph are not on a shared business scale. Betweenness depends on graph size/path structure; community IDs are labels; similarity metrics have distinct normalization. “Score 12 is twice as important as score 6” is often unsupported.

Repair by interpreting within the algorithm/projection context, using percentiles or rank where justified, and comparing against baselines on the same task. If cross-graph comparability is a requirement, design a validated normalization/calibration scheme rather than assuming raw outputs are portable.

7. Exploration versus production decision support

Dimension Exploration Production decision support
Projection Fast bounded hypothesis graph Versioned reproducible specification with freshness/SLO
Mode stream/stats preferred write only when downstream contract and rollback are defined
Validation Hand fixture + qualitative inspection Ground truth/holdout/baseline + sensitivity + drift monitoring
Resources Manual estimate/observation Capacity envelope, concurrency budget, alerts and isolation
Interpretation Generate hypotheses Governed claim with explicit non-guarantees and audit trail
Refresh Ad hoc Scheduled/event-driven with source cutoff and lineage

8. Production checklist across the Neo4j stack

Area Chapter 24 gate
Graph/workload fit Algorithms answer topology questions that would be awkward/expensive to derive repeatedly from transactional patterns.
Correctness Projection schema/orientation/weights and domain identities are documented; no internal IDs as durable keys.
Cardinality/degree Node/relationship counts and degree distribution recorded; hubs/outliers investigated.
Transactions/concurrency GDS work isolated from transaction latency; Community max concurrency four respected.
Memory/CPU/disk/network Projection and algorithm estimates plus measured process memory/CPU; data movement/result size included.
Indexes/constraints Source identities/invariants protected in Neo4j; indexes support projection/source preparation where relevant.
Driver/timeouts/retries If automated by an app, jobs have bounded timeouts/idempotent orchestration and do not duplicate persistent writes on retry.
Security/tenant risk Projection does not combine data the caller is not entitled to analyze; GDS unrestricted procedure surface is governed.
Backup/recovery Transactional source is backed up; in-memory projections are reconstructible analytical state.
Observability JobId/progress, estimate, compute timing, failure, projection lifecycle, refresh age and output distribution monitored.
Version/edition/tier Neo4j/GDS compatibility pinned; Aura/Enterprise features not silently assumed in Community lab.
Migration/rollback New algorithm/version is shadow-evaluated; previous decision artifact retained until validation passes.

9. Chapter 24 final verification checklist

  1. Run RETURN gds.version() and record the exact version.
  2. For each projection, record node count, relationship count, orientation, projected properties, and degree distribution.
  3. Run an *.estimate form for the chosen algorithm before scale testing.
  4. Validate at least one output manually: Degree, Jaccard, or a shortest route.
  5. Run at least one baseline and one sensitivity experiment.
  6. State what the output proves and what it does not prove.
  7. Prefer stream/stats until persistent writes are explicitly justified.
  8. Drop Chapter-24 projections and delete only Chapter-24 fixtures.
Chapter 24 cleanup/reset
// Drop all Chapter 24 in-memory projections first.
CALL gds.graph.list()
YIELD graphName
WITH graphName WHERE graphName STARTS WITH 'atlas-ch24-'
CALL gds.graph.drop(graphName) YIELD graphName AS dropped
RETURN dropped;

// Then delete only synthetic Chapter 24 persisted fixtures.
MATCH (n)
WHERE n.chapter24 = true
DETACH DELETE n;

MATCH (n) WHERE n.chapter24 IS NOT NULL REMOVE n.chapter24;
RETURN 'Chapter 24 reset complete' AS status;

10. Bridge to Chapter 25: algorithms become features, and leakage becomes the next risk

Chapter 24 produces structural scores, communities, similarities, and paths. Chapter 25 will use topology and graph-algorithm outputs as embeddings/features in machine-learning workflows. The analytical discipline carries forward: projection cutoff, train/test separation, reproducible randomness, feature leakage, model catalog limits, and non-graph baselines all become mandatory. A graph feature is useful only if it adds measured predictive signal without leaking future or target information.

Check your understanding

  1. What should determine the algorithm family first?
  2. Why is stream the default first mode in this chapter?
  3. What is the minimum validation pattern before scaling?
  4. Why is sensitivity testing part of correctness?
  5. What does Chapter 25 add to the risk surface?
Review the answers

1. The decision question and a falsifiable structural hypothesis, not algorithm popularity.

2. It exposes results without mutating the in-memory projection or persistent Neo4j store, making exploration easier to verify/rollback.

3. A hand-checkable fixture or exact simple baseline plus projection/configuration evidence.

4. Heuristic/approximate/parameterized algorithms can materially change rankings/partitions/candidates when data, seeds, resolution, weights or orientation change.

5. Embeddings/ML introduce train-test splits, leakage, model selection, predictive metrics and model lifecycle on top of the graph/projection assumptions.

Summary and next step

Choose an Algorithm from the Decision Question, Validate Assumptions, and Interpret Results Without Overclaiming is useful only when its assumptions and observed evidence stay attached to the decision. The examples above establish a reproducible mechanism and boundary; they do not turn one lab result into a universal production rule.

Next, continue to Node Embeddings from Topology/Properties, FastRP/Node2Vec-Like Concepts, Dimensions, and Reproducibility. Carry forward the verified assumptions, fixture state, version/edition boundaries, and measurements from this lesson instead of treating the next topic as an isolated recipe.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.