function res = collectLeaves(atree)
% the tree nodes may have many children
if isleaf(atree)
    res = {atree.key};
else
    for j=2:length(atree)
        res = [res, collectLeaves(atree{j})]
    end;
end;