Table of Contents

Method BuildMST

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

BuildMST(int, MSTEdge[], MSTAlgorithm, int)

Builds a Minimum Spanning Tree (MST) using the specified algorithm.

Supports graphs with negative edge weights. Self-loop edges (edges where source and target are the same) are ignored. If multiple edges exist between the same pair of nodes, only the one with the lowest weight is considered. If the graph is disconnected or input is invalid, the function returns false.

public static MSTEdge[]? BuildMST(int numNodes, MSTEdge[] inputEdges, MSTAlgorithm algorithm, int root = 0)

Parameters

numNodes int

Number of nodes in the graph (must be greater than 0).

inputEdges MSTEdge[]

Input array of edges representing the graph.

algorithm MSTAlgorithm

Specifies which algorithm to use to compute the MST.

root int

Starting node for the MST algorithm (only used for certain algorithms).

Returns

MSTEdge[]

The edges of the resulting MST, or null if a valid MST could not be built.