Determine nonterminal nodes
N = noleaves(
T
)
N = noleaves(T
,'dp')
N = noleaves(
returns
the indices of nonterminal nodes of the tree T
)T
(i.e.,
nodes that are not leaves). N
is a column vector.
The nodes are ordered from left to right as in tree T
.
N = noleaves(
returns
a matrix T
,'dp')N
, which contains the depths and positions
of nonterminal nodes.
N(i,1)
is the depth of the i
-th
nonterminal node and
N(i,2)
is
the position of the i
-th nonterminal node.
% Create initial tree.
ord = 2;
t = ntree(ord,3); % binary tree of depth 3.
t=nodejoin(t,5);
t=nodejoin(t,4);
plot(t)
% Change Node Label from Depth_Position to Index
% (see the plot
function).
% List nonterminal nodes (index). ntnodes_ind = noleaves(t) ntnodes_ind = 0 1 2 3 6 % List nonterminal nodes (Depth_Position). ntnodes_depo = noleaves(t,'dp') ntnodes_depo = 0 0 1 0 1 1 2 0 2 3