Skip to content

Algorithm Concepts

Tutorial

Algorithm Concepts

Introduction to graph algorithms and when to use them

15 min Beginner
AlgorithmsIntroduction

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 — Parameters
USERNAME = "_FILL_ME_IN_" # Set your email before running
# Cell 2 — Connect
from graph_olap import GraphOLAPClient
client = GraphOLAPClient(username=USERNAME)
# Cell 3 — Provision
from notebook_setup import provision
personas, 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")
1

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:

CategoryPurposeExample
CentralityRank nodes by importancePageRank, Degree Centrality
Community DetectionFind clusters of related nodesLouvain, Label Propagation
PathfindingDiscover shortest or optimal routesShortest Path, All Paths
StructuralMeasure graph topologyConnected 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 algorithms
algos = conn.algo.algorithms()
print("Available native algorithms:")
for name in algos:
print(f" - {name}")
2

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 node
result = conn.algo.pagerank(
node_label="Customer",
property_name="intro_pr",
edge_type="SHARES_ACCOUNT",
)
# Inspect the AlgorithmExecution result object
print(f"Algorithm : {result.algorithm}")
print(f"Status : {result.status}")
print(f"Nodes : {result.nodes_updated}")
3

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 node
df = conn.query_df("""
MATCH (c:Customer)
RETURN c.id AS name,
round(c.intro_pr, 4) AS pagerank
ORDER BY c.intro_pr DESC
""")
df

MR 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.

4

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 interfaces
native_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 comparison
print("\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 AlgorithmExecution result gives you status, node count, and algorithm name
  • Use conn.algo for fast native algorithms (PageRank, Louvain, WCC)
  • Use conn.networkx for the full NetworkX library (100+ algorithms)