function Minb = NRTmin(Sbar, N)
% Octave/MATLAB function to compute minimums
% along paths in a non-recombining tree (NRT).
% INPUTS:                             (Example)
%   Sbar = NRT array of length 2*2^N-1   (1:15)
%   N = tree depth, must be >=0             (3)
% OUTPUT:
%   Minb = NRT of minimums, same size as Sbar
% EXAMPLE:
%  Minb = NRTmin(1:15,3)
%
  Minb=zeros(size(Sbar)); % allocate the output
  Minb(1)=Sbar(1); % min along the trivial path
  for m=1:2^N-1   % all future times up to N-1
    Minb(2*m)=min(Minb(m),Sbar(2*m));   % down
    Minb(2*m+1)=min(Minb(m),Sbar(2*m+1)); % up
  end
  return
end
