Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

depo2ind

Node depth-position to node index

Syntax

Description

depo2ind is a tree-management utility.

For a tree of order ORD, N = depo2ind(ORD,[D P]) computes the indices N of the nodes whose depths and positions are encoded within [D,P].

The nodes are numbered from left to right and from top to bottom. The root index is 0.

D and P are column vectors. The values of depths D and positions P must be such that D ≥0 and 0≤ PORDD-1.

Output indices N are such that 0 ≤ N < (ORDmax(D)-1)/ORD–1.

Note that for a column vector X, we have depo2ind(O,X) = X.

Examples

% Create initial tree. 
ord = 2; 
t = ntree(ord,3);     % binary tree of depth 3. 
t = nodejoin(t,5); 
t = nodejoin(t,4); 
plot(t)

% List t nodes (Depth_Position). 
aln_depo = allnodes(t,'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

Introduced before R2006a

Was this topic helpful?