function dfs ( adj, label, start )

%% DFS conducts a depth-first search of a graph.
%
%  Input, ADJ(N,N), the adjacency matrix.
%
%  Input, LABEL(N), is a list of labels for the nodes.
%
%  Input, START, the index of the starting node.
%

%
%  Get number of nodes.
%
  [ n, n ] = size ( adj );

  list = start;
  visited = zeros ( n, 1 );
  visited(start) = true;
%
%  As long as there are nodes on our list...
%
  while ( 0 < length ( list ) )
%
%  ...get the most recently encountered node...
%
    j = list(end);
    fprintf ( ' %s\n', label(j) );
%
%  ...remove it from the list, and...
%
    list = list(1:end-1);
%
%  ...search in all directions...
%
    for k = 1 : n
%
%  ...for an adjacent, unvisited node to add to the list.
%
      if ( adj(k,j) & ~ visited(k) )
        visited(k) = true;
        list = [ list, k ];
      end

    end 

  end

  fprintf ( '\n' );
  fprintf ( 'DFS concluded.\n' );

  return
end
