Table of Contents

Class GraphConnectivityExtensions

Namespace
Graph1x.Algorithms
Assembly
Graph1x.dll

Connectivity queries: connected components (edge direction ignored), weak connectivity for directed graphs, and strongly connected components via an iterative Tarjan algorithm.

public static class GraphConnectivityExtensions
Inheritance
GraphConnectivityExtensions
Inherited Members

Methods

ConnectedComponents<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>)

Computes the connected components of the graph, ignoring edge direction (for directed graphs this is weak connectivity).

public static IReadOnlyList<IReadOnlySet<TVertex>> ConnectedComponents<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> graph) where TVertex : notnull where TEdge : IEdge<TVertex>

Parameters

graph IReadOnlyGraph<TVertex, TEdge>

The graph to partition.

Returns

IReadOnlyList<IReadOnlySet<TVertex>>

One vertex set per component.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

FindArticulationPoints<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>)

Finds the articulation points (cut vertices) of an undirected graph: vertices whose removal increases the number of connected components.

public static IReadOnlySet<TVertex> FindArticulationPoints<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> graph) where TVertex : notnull where TEdge : IEdge<TVertex>

Parameters

graph IReadOnlyGraph<TVertex, TEdge>

The undirected graph to inspect.

Returns

IReadOnlySet<TVertex>

The articulation points.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

Exceptions

ArgumentException

graph is directed.

FindBridges<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>)

Finds the bridges of an undirected graph: edges whose removal increases the number of connected components. A parallel edge pair is never a bridge; self-loops are ignored.

public static IReadOnlyList<TEdge> FindBridges<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> graph) where TVertex : notnull where TEdge : IEdge<TVertex>

Parameters

graph IReadOnlyGraph<TVertex, TEdge>

The undirected graph to inspect.

Returns

IReadOnlyList<TEdge>

The bridge edges.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

Exceptions

ArgumentException

graph is directed.

IsConnected<TVertex, TEdge>(IReadOnlyGraph<TVertex, TEdge>)

Determines whether the graph is connected when edge direction is ignored. The empty graph is trivially connected.

public static bool IsConnected<TVertex, TEdge>(this IReadOnlyGraph<TVertex, TEdge> graph) where TVertex : notnull where TEdge : IEdge<TVertex>

Parameters

graph IReadOnlyGraph<TVertex, TEdge>

The graph to inspect.

Returns

bool

true if there is at most one component.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

StronglyConnectedComponents<TVertex, TEdge>(IDirectedGraph<TVertex, TEdge>)

Computes the strongly connected components of a directed graph using Tarjan's algorithm (iterative, stack-safe on deep graphs). Components are emitted in reverse topological order of the condensation.

public static IReadOnlyList<IReadOnlySet<TVertex>> StronglyConnectedComponents<TVertex, TEdge>(this IDirectedGraph<TVertex, TEdge> graph) where TVertex : notnull where TEdge : IEdge<TVertex>

Parameters

graph IDirectedGraph<TVertex, TEdge>

The directed graph to partition.

Returns

IReadOnlyList<IReadOnlySet<TVertex>>

One vertex set per strongly connected component.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.

WeaklyConnectedComponents<TVertex, TEdge>(IDirectedGraph<TVertex, TEdge>)

Computes the weakly connected components of a directed graph: the connected components after forgetting edge direction.

public static IReadOnlyList<IReadOnlySet<TVertex>> WeaklyConnectedComponents<TVertex, TEdge>(this IDirectedGraph<TVertex, TEdge> graph) where TVertex : notnull where TEdge : IEdge<TVertex>

Parameters

graph IDirectedGraph<TVertex, TEdge>

The directed graph to partition.

Returns

IReadOnlyList<IReadOnlySet<TVertex>>

One vertex set per component.

Type Parameters

TVertex

The vertex type.

TEdge

The edge type.