Algorithm Concepts
Algorithm Concepts
Introduction to graph algorithms and when to use them
What You'll Learn
- Algorithm Categories - Centrality, community detection, pathfinding, structural
- When to Use - Choosing the right algorithm for your question
- How Results Work - Properties stored on nodes after execution
# Cell 1 — ParametersUSERNAME = "_FILL_ME_IN_" # Set your email before running# Cell 2 — Connectfrom graph_olap import GraphOLAPClientclient = GraphOLAPClient(username=USERNAME)
# Cell 3 — Provisionfrom notebook_setup import provisionpersonas, conn = provision(USERNAME)analyst = personas["analyst"]admin = personas["admin"]ops = personas["ops"]client = analyst
print(f"Connected | {conn.query_scalar('MATCH (n) RETURN count(n)')} nodes")What Are Graph Algorithms?
Categories and when to use them
Graph algorithms analyse the structure and relationships in a graph to surface insights that simple queries cannot reveal. They fall into four main categories:
| Category | Purpose | Example |
|---|---|---|
| Centrality | Rank nodes by importance | PageRank, Degree Centrality |
| Community Detection | Find clusters of related nodes | Louvain, Label Propagation |
| Pathfinding | Discover shortest or optimal routes | Shortest Path, All Paths |
| Structural | Measure graph topology | Connected Components, Triangle Count |
In banking, these algorithms help identify influential customers, detect related-party networks, find isolated account clusters, and map transaction flows.
# Discover available native algorithmsalgos = conn.algo.algorithms()print("Available native algorithms:")for name in algos: print(f" - {name}")Running Your First Algorithm
Execute PageRank and understand the result object
Every algorithm call returns an AlgorithmExecution object with metadata about the run.
The algorithm writes its scores directly to a named property on each node.
# Run PageRank — results are written to the "intro_pr" property on each Customer noderesult = conn.algo.pagerank( node_label="Customer", property_name="intro_pr", edge_type="SHARES_ACCOUNT",)
# Inspect the AlgorithmExecution result objectprint(f"Algorithm : {result.algorithm}")print(f"Status : {result.status}")print(f"Nodes : {result.nodes_updated}")Reading Results
Query algorithm output with Cypher
Because algorithms store their output as node properties, you read the results using
standard Cypher queries. The query_df method returns a Polars DataFrame for
convenient tabular display.
# Query the PageRank scores stored on each Customer nodedf = conn.query_df(""" MATCH (c:Customer) RETURN c.id AS name, round(c.intro_pr, 4) AS pagerank ORDER BY c.intro_pr DESC""")
dfMR LAU XIAOMING and KWONG XIAO TONG score highest because they each have 3 shared-account relationships (degree 3), giving them more incoming “votes” in the PageRank iteration. The remaining three customers share 2 connections each.
Native vs NetworkX Algorithms
conn.algo for speed, conn.networkx for breadth
The SDK provides two algorithm interfaces:
conn.algo— Native algorithms executed inside the graph engine. Faster, but limited to a curated set (PageRank, Louvain, Connected Components, etc.).conn.networkx— Algorithms from the NetworkX library. The graph is exported to NetworkX, the algorithm runs in Python, and results are written back. Slower on large graphs, but provides access to 100+ algorithms (betweenness centrality, closeness centrality, clustering coefficient, and many more).
# Compare the two interfacesnative_count = len(conn.algo.algorithms())nx_algos = conn.networkx.algorithms()print(f"Native algorithms : {native_count}")print(f"NetworkX algorithms: {len(nx_algos)}+")
# Run a NetworkX algorithm for comparisonprint("\nExample NetworkX call \u2014 degree centrality:")nx_result = conn.networkx.degree_centrality( node_label="Customer", property_name="intro_dc",)print(f"Status: {nx_result.status}, Nodes updated: {nx_result.nodes_updated}")Key Takeaways
- Algorithms write results to node properties — query them with Cypher afterwards
- The
AlgorithmExecutionresult gives you status, node count, and algorithm name - Use
conn.algofor fast native algorithms (PageRank, Louvain, WCC) - Use
conn.networkxfor the full NetworkX library (100+ algorithms)