Node depth-position to node index.
Syntax
N = depo2ind(O,[D P])
Description
depo2ind is a tree management utility.
For a tree of order O, N = depo2ind(O,[D P]) computes the indices N of the nodes whose depths and positions are encoded within [D,P].
D, P and N are column vectors. The values of D, P and N are constrained by:
D = depths, 0
D
dmax
P = positions at depth D, 0
P
orderD-1
N = indices, 0
N < (order(dmax+1)-1)/(order-1)
Note that for a column vector X, we have depo2ind(O,X) = X.
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 tt nodes (depth-position).
aln_depo = allnodes(tt,'deppos')
aln_depo =
0 0
1 0
1 1
2 0
2 1
2 2
2 3
3 0
3 1
3 6
3 7
% Switch from depth-position to index.
aln_ind = depo2ind(ord,aln_depo)
aln_ind =
0
1
2
3
4
5
6
7
8
13
14
See Also
ind2depo, maketree, wtreemgr
[ Previous | Help Desk | Next ]