yog/properties/clique

Clique finding algorithms using the Bron-Kerbosch algorithm.

A clique is a subset of nodes where every pair of nodes is connected by an edge. Cliques represent tightly-knit communities or fully-connected subgraphs.

Algorithms

ProblemAlgorithmFunctionComplexity
Maximum cliqueBron-Kerbosch with pivotmax_clique/1O(3^(n/3))
All maximal cliquesBron-Kerboschall_maximal_cliques/1O(3^(n/3))
k-CliquesBron-Kerbosch with pruningk_cliques/2O(3^(n/3))

Key Concepts

The Bron-Kerbosch Algorithm

A backtracking algorithm that recursively explores potential cliques using three sets:

Pivoting optimization: Choose a pivot vertex to reduce recursive calls, achieving the worst-case optimal O(3^(n/3)) bound.

Complexity Notes

Finding the maximum clique is NP-hard. The O(3^(n/3)) bound is tight - there exist graphs with exactly 3^(n/3) maximal cliques (Moon-Moser graphs).

Related Problems

Use Cases

References

Values

pub fn all_maximal_cliques(
  graph: model.Graph(n, e),
) -> List(set.Set(Int))

Finds all maximal cliques in an undirected graph.

A maximal clique is a clique that cannot be extended by adding another node.

Time Complexity: O(3^(n/3)) worst case

Example

clique.all_maximal_cliques(graph)
// => [set.from_list([1, 2]), set.from_list([2, 3])]
pub fn k_cliques(
  graph: model.Graph(n, e),
  k: Int,
) -> List(set.Set(Int))

Finds all cliques of exactly size k in an undirected graph.

Uses a modified Bron-Kerbosch algorithm with early pruning.

Time Complexity: O(3^(n/3)) worst case

Example

clique.k_cliques(graph, 3)
// => [set.from_list([1, 2, 3])]
pub fn max_clique(graph: model.Graph(n, e)) -> set.Set(Int)

Finds the maximum clique in an undirected graph.

Returns the largest subset of nodes where every pair is connected.

Time Complexity: O(3^(n/3)) worst case

Example

clique.max_clique(graph)
// => set.from_list([1, 2, 3, 4])
Search Document