function check = pruefer_check ( n, p )

%*****************************************************************************80
%
%% pruefer_check() checks a Pruefer code.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    25 January 2011
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Donald Kreher, Douglas Simpson,
%    Combinatorial Algorithms,
%    CRC Press, 1998,
%    ISBN: 0-8493-3988-X,
%    LC: QA164.K73.
%
%  Input:
%
%    integer N, the number of nodes in the tree.
%    N must be at least 3.
%
%    integer P(N-2), the Pruefer code for the tree.
%
%  Output:
%
%    boolean CHECK.
%    true, the data is legal.
%    false, the data is not legal.
%
  check = true;

  if ( n < 3 )
    check = false;
    return
  end

  for i = 1 : n - 2
    if ( p(i) < 1 || n < p(i) )
      check = false;
      return
    end
  end

  return
end
