Node index to node depth-position.
Syntax
[D,P] = ind2depo(ORD,N)
Description
ind2depo is a tree management utility.
For a tree of order ORD, [D,P] = ind2depo(ORD,N) computes the depths D and the positions P (at this depths D) for the nodes with indices N.
The nodes are numbered from left to right and from top to bottom. The root index is 0.
D, P, N are column vectors. The values of D, P, 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 [D,P] = ind2depo(ORD,[D P]).
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 (index).
aln_ind = allnodes(tt)
aln_ind =
0
1
2
3
4
5
6
7
8
13
14
% Switch from index to depth-position.
[depth,pos] = ind2depo(ord,aln_ind);
aln_depo = [depth,pos]
aln_depo =
0 0
1 0
1 1
2 0
2 1
2 2
2 3
3 0
3 1
3 6
3 7
See Also
depo2ind, maketree, wtreemgr
[ Previous | Help Desk | Next ]