Cody

# Problem 2730. Graph Algorithms 3: Number of Connected Components

Solution 679119

Submitted on 2 Jun 2015 by Gergely Patay
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% a = ones(3) - eye(3); b = zeros(3); mat = [a b; b a]; n = 2; assert(isequal(cComponents(mat),n))

2   Pass
%% a = randi(20); mat = ones(a) - eye(a); n = 1; assert(isequal(cComponents(mat),n))

3   Pass
%% mat = [0 1 0 0 1; 1 0 1 0 0; 0 1 0 1 0; 0 0 1 0 1; 1 0 0 1 0]; assert(isequal(cComponents(mat),1))

4   Pass
%% a = ones(3) - eye(3); b = zeros(3); mat = [a b b; b a b; b b a]; n = 3; assert(isequal(cComponents(mat),n))

5   Pass
%% a = ones(3) - eye(3); b = zeros(3); p = floor((randi(20)+3)/3)*3; mat = []; for i= 1:p c = [repmat(b,1,i-1) a repmat(b,1,p-i)]; mat = [mat;c]; end assert(isequal(cComponents(mat),p))

### Community Treasure Hunt

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

Start Hunting!