function d = distance_from_a ( adj, a )
%
%% DISTANCE_FROM_A computes the distance from node A to all nodes in the graph.
%
%  ADJ(N,N) is the adjacency matrix for the graph G.
%
%  A is a node in the graph.
%
%  D(I) is the distance from node A to node I.
%  D(A) = 0.  
%  If node I is unreachable, D(I) = Inf.
%

%
%  How many nodes are there?
%
  [ n, n ] = size ( adj );
%
%  Set up D.
%
  d(1:n,1) = Inf;
  distance = 0;
  d(a) = distance;
%
%  NEW holds the nodes we have just reached on this step.
%
  new = [ a ];

  while ( 0 < length ( new ) )

    old = new;
    new = [];
    distance = distance + 1;
%
%  For each node J that we found on the previous step...
%
    for k = 1 : length ( old )
      j = old(k);
%
%  ...look for adjacent neighbors I...
%
      for i = 1 : n

        if ( adj(i,j) == 1 )
%
%  ...and if node I hasn't been reached yet:
%  mark that is has been reached,
%  add it to list,
%  and increase the count of nodes we have reached.
%
          if ( d(i) == Inf )
            d(i) = distance;
            new = [ new, i ];
          end

        end
      end

    end

  end

  return
end
