UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Community Detection

Max k-Cut

Overview

The Max k-Cut algorithm partitions the nodes of a graph into k groups such that the number of edges between different groups is maximized. It uses a greedy local search approach: starting from a random partition, it iteratively moves each node to the partition that maximizes the cut size.

Unlike community detection algorithms that maximize intra-group connectivity, Max k-Cut maximizes inter-group edges. It has applications in network design, VLSI layout, and frequency assignment.

Concepts

Maximum k-Cut

Given a graph and an integer k, the maximum k-cut problem seeks to partition the nodes into k disjoint sets such that the total number of edges crossing between sets is maximized. When k = 2, this is the classic maximum cut problem.

In this example with k = 2, the optimal cut places nodes {A, D} in one partition and {B, C, E} in the other, cutting 5 of the 6 edges.

The Max k-Cut problem is NP-hard, so the algorithm uses an approximation via local search that converges to a locally optimal solution.

Considerations

  • The algorithm treats all edges as undirected.
  • Results may vary between runs due to random initialization.

Example Graph

GQL
INSERT (A:default {_id: "A"}), (B:default {_id: "B"}),
       (C:default {_id: "C"}), (D:default {_id: "D"}),
       (E:default {_id: "E"}), (F:default {_id: "F"}),
       (G:default {_id: "G"}), (H:default {_id: "H"}),
       (A)-[:default]->(B), (A)-[:default]->(C),
       (A)-[:default]->(D), (A)-[:default]->(E),
       (A)-[:default]->(G), (D)-[:default]->(E),
       (D)-[:default]->(F), (E)-[:default]->(F),
       (G)-[:default]->(D), (G)-[:default]->(H)

Parameters

NameTypeDefaultDescription
kINT2Number of partitions (≥ 2).
iterationsINT100Number of local search iterations.
limitINT-1Limits the number of results returned (-1 = all).
orderSTRING/Sorts the results by partition: asc or desc.

Run Mode

Returns:

ColumnTypeDescription
nodeIdSTRINGNode identifier (_id)
partitionINTPartition assignment
cutSizeFLOATTotal number of edges crossing between partitions
GQL
CALL algo.maxkcut({
  k: 3
}) YIELD nodeId, partition, cutSize

Result:

nodeIdpartitioncutSize
E210
D010
G210
F110
A110
C010
B010
H010

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.maxkcut.stream({
  k: 2
}) YIELD nodeId, partition
RETURN partition, COLLECT(nodeId) AS members
GROUP BY partition

Result:

partitionmembers
1[E, D, C, B, H]
0[G, F, A]

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
partitionCountINTNumber of partitions
cutSizeFLOATTotal number of edges crossing between partitions
GQL
CALL algo.maxkcut.stats({
  k: 2
}) YIELD nodeCount, partitionCount, cutSize

Result:

nodeCountpartitionCountcutSize
828

Write Mode

Computes results and writes them back to node properties. The write configuration is passed as a second argument map.

Write parameters:

NameTypeDescription
db.propertySTRING or MAPNode property to write results to. String: writes the partition column in results to a property. Map: explicit column-to-property mapping (e.g., {partition: 'cut_group'}).

Writable columns:

ColumnTypeDescription
partitionINTPartition assignment

Returns:

ColumnTypeDescription
task_idSTRINGTask identifier for tracking via SHOW TASKS
nodesWrittenINTNumber of nodes with properties written
computeTimeMsINTTime spent computing the algorithm (milliseconds)
writeTimeMsINTTime spent writing properties to storage (milliseconds)
GQL
CALL algo.maxkcut.write({k: 3}, {
  db: {
    property: "cut_group"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs