Terminal nodes.
Syntax
N = tnodes(T)
N = tnodes(T,'deppos')
[N,K] = tnodes(T)
[N,K] = tnodes(T,'deppos')
Description
tnodes is a tree management utility.
N = tnodes(T) returns the indices of terminal nodes of the tree structure T
(see maketree). N is a column vector.
The nodes are numbered from left to right and from top to bottom. The root index is 0.
N = tnodes(T,'deppos') returns a matrix N which contains the depths and positions of terminal nodes.
N(i,1) is the depth of i-th terminal node. N(i,2) is the position of i-th terminal node.
For [N,K] = tnodes(T) or [N,K] = tnodes(T,'deppos'), M = N(K) are the indices reordered in tree T, from left to right.
Examples
% Create initial tree.
ord = 2; t = maketree(ord,3); % Binary tree of depth 3.
tt = nodejoin(t,5);
tt = nodejoin(tt,4);
plottree(tt)
% List terminal nodes (index).
tnodes(tt)
ans =
4
5
7
8
13
14
% List terminal nodes (depth-position).
tnodes(tt,'deppos')
ans =
2 1
2 2
3 0
3 1
3 6
3 7
See Also
maketree, wtreemgr
[ Previous | Help Desk | Next ]