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_nposter should be transverse andi_1,i_2...i_nInverters can be traversal from postorder traversal They are the root of the tree,p_nfind this element in Insider Traversal,i_1,i_2...< Code> i_k-1say p_ni_k + 1...i_n. From Inner Travelers we find all the elements in the left subsection, i.e.i_1,i_2...i_k-1and in the correct subtree, i.e.i_k + 1...i_n.element
P_n (and element i_k==p_n). Correct code inp_jinp_1,p_2...p_j... p_n-1wherep_jis 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_jandp_j + 1...p_n-1andi_1,i_2...i_k-1and < 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