algorithm - Construct a Tree -
How do I build a tree, so that the inside and the preder are transverse? I'm just searching for a skilled algorithm.
A clear copy and paste:
< Strong> Question:
p_1 , p_2
...
p_n
poster should be transverse andi_1
,i_2
...
i_n
Inverters can be traversal from postorder traversal They are the root of the tree,p_n
find this element in Insider Traversal,i_1
,i_2
...
< Code> i_k-1say p_n
i_k + 1
...
i_n
. From Inner Travelers we find all the elements in the left subsection, i.e.i_1
,i_2
...
i_k-1
and in the correct subtree, i.e.i_k + 1
...
i_n
.element
P_n (and element i_k
==
p_n
). Correct code inp_j
inp_1
,p_2
...
p_j
... p_n-1
wherep_j
is an element ini_1
,i_2
. .i_k-1
. This is the root of the original tree's left subtitle. Splitp_1
,p_2
...
p_j
andp_j + 1
...p_n-1
andi_1
,i_2
...
i_k-1
and < Code> i_k + 1...
i_n
. You now have two repeaters representing two sub-parts post orders and indoor traversal of the original post.Author :.
I have applied the algorithm once more, and it worked perfectly!
Comments
Post a Comment