components matlab,components.m

function [ci sizes] = components(A,varargin)

% COMPONENTS Compute the connected components of a graph.

%

% [ci sizes] = components(A) returns the component index vector (ci) and

% the size of each of the connected components (sizes). The number of

% connected components is max(components(A)). The algorithm used computes

% the strongly connected components of A, which are the connected

% components of A if A is undirected (i.e. symmetric).

%

% This method works on directed graphs.

% The runtime is O(V+E), the algorithm is just depth first search.

%

% ... = components(A,...) takes a set of

% key-value pairs or an options structure. See set_matlab_bgl_options

% for the standard options.

% There are no additional options for this function.

%

% Note: this function does not depend upon the non-zero values of A, but

% only uses the non-zero structure of A.

%

% Example:

% load('graphs/dfs_example.mat');

% components(A)

%

% See also DMPERM, BICONNECTED_COMPONENTS

% David Gleich

% Copyright, Stanford University, 2006-2008

%% History

% 2006-04-21: Initial version

% 2006-05-31: Added full2sparse check

% 2006-11-09: Fixed documentation typo.

% 2007-07-08: Code cleanup

%%

[trans check full2sparse] = get_matlab_bgl_options(varargin{:});

if full2sparse && ~issparse(A), A = sparse(A); end

if check, check_matlab_bgl(A,struct()); end

if trans, A = A'; end

[ci sizes] = components_mex(A);

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值