Connected graph given adjacency matrix

24 ビュー (過去 30 日間)
imperial1991
imperial1991 2012 年 5 月 29 日
回答済み: Hon Wah Yeung 2021 年 1 月 31 日
Hi all, I'm working on a research project on graphical models involving a large dimension (large number of nodes). I'm just wondering, is there an existing efficient algorithm to determine whether the graph is connected or not given its adjacency matrix? I've tried looking but it seems that the existing ones are brute force algorithms which are costly. Does MATLAB have a built-in function? When I checked, it seems that none exists as of now.
Help would be greatly appreciated!

採用された回答

Wolfgang Schwanghart
Wolfgang Schwanghart 2012 年 5 月 29 日
You can use the function dmperm to see if a graph consists of one or several connected components. E.g. see the example here http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/
HTH, W.
  1 件のコメント
imperial1991
imperial1991 2012 年 5 月 30 日
Hi wolfgang, this is great! thanks a lot!

サインインしてコメントする。

その他の回答 (3 件)

Christine Tobler
Christine Tobler 2016 年 12 月 22 日
編集済み: Christine Tobler 2019 年 11 月 22 日
I realize this is an old question, but since it's still getting visits, I have a small addition. As of R2015b, the new graph and digraph classes have a method for computing connected components. To check whether a graph is connected based on its adjacency matrix A, use
g = digraph(A);
bins = conncomp(g, 'Type', 'weak');
isConnected = all(bins == 1);
The vector bins gives the bin number for each node of A. If a graph is connected, all nodes will be in one bin, which is checked using all(bins == 1). This is not necessarily faster than dmperm, but easier to read.
  2 件のコメント
Jonathan DuBois
Jonathan DuBois 2017 年 8 月 24 日
What is the point of the first command? Should it be: bins = conncomp(g, 'Type', 'weak')? It works with g in the second command but with A, I get the following error: Undefined function 'conncomp' for input arguments of type 'double'.
Christine Tobler
Christine Tobler 2019 年 11 月 22 日
Thank you, yes, this was a typo. I've edited the original answer to fix this (although it took me two years to realize you had commented on this answer).

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2012 年 5 月 29 日
try grTheory - Graph Theory Toolbox by Sergii Iglin
  1 件のコメント
imperial1991
imperial1991 2012 年 5 月 30 日
hi andrei, it seems like there's no function for checking whether a graph is connected or not. thanks anyway!

サインインしてコメントする。


Hon Wah Yeung
Hon Wah Yeung 2021 年 1 月 31 日
This will work if you can at least load the matrix (meaning the matrix is not larger than the max possible array for Matlab) to Matlab.
function [idx,Group] = CheckConnected(E)
L=length(E);
T=find(E(:,1)~=0);
T=[T;1]';
M=sum(E(:,T),2);
T1=union(find(M~=0),T);
while length(T1)>length(T)
T=T1;
M=sum(E(:,T),2);
T1=union(find(M~=0),T);
end
if length(T)==L
idx=1;
Group=T;
else
idx=0;
Group=T;
end
end

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by