function y = peripheral_node(A) % function y = peripheral_node(A) % given a square, sparse symmetric matrix A, find the % pesudo-peripheral node using the Algorithm by George and Liu. % NB. I need to explain what a peripheral node is later. L_old = 0; L_new = 1; [M,N] = size(A); link = zeros(M,1); for k = 1:M link(k) = sum(A(k,:)~=0) - 1; end [Y,I] = sort(link); x = I(end); % pick initial guess % pick a random starting node % x = ceil(M*rand); while (L_new > L_old) L_old = L_new; % create the tree l{1} = x; % create test vector e = zeros(1,M); e(l{1}) = 1; % set counter variables k = 2; n = 1; while (sum(e>0) < M) % initialize next tree l{k} = []; for j = 1:n v = (A(l{k-1}(j),:)~=0); % store new level. This is actually redundant because % all we care about is the last level which gives us the % pseudo peripheral node. l{k} = [l{k} find((v-e)>0)]; e = e+v; e = (e~=0); % stop loop if we've found all links if (sum(e>0) == M) j = n; end end [m,n] = size(l{k}); % if no new links are found, stop loop. if (n == 0) e = ones(1,M); k = k-1; % needed for accounting purposes end k = k+1; end L_new = k-1; [Y,I]=sort(l{L_new}); x = l{L_new}(I(1)); end y = l{1};