function res = treedepth(tree)
% treedepth(tree)- maximum depth of tree
if isleaf(tree) 
   res = 0; %! A node has no depth
else
   bdepths = zeros(length(tree.branches),1);
   %!! Find the depths of the branches
   for k=1:length(tree.branches)
      bdepths(k) = treedepth(tree.branches{k});
   end
   res = 1 + max(bdepths);
   %!! Total depth: 1 + the maximum branch's depth
end
