Preamble binary tree, in sequence, after traversing (study notes)

Preamble binary tree, in sequence, after traversing the
binary tree refer to related concepts: https: //baike.baidu.com/item/%E4%BA%8C%E5%8F%89%E6%A0%91/1602879 ? fr = aladdin

Binary tree: preorder traversal ABDFGHIEC
             
            

Preorder FDHGIBEAC

Postorder FHIGDEBCA

Example 1:
    Known preamble is a binary tree traversal ABDFGHIEC, inorder traversal of FDHGIBEAC, Fengyun restore binary tree.
    
    Problem-solving ideas:
        the former preorder traversal, we determined the root node A, come in from the left FDEBC order traversal of the root, C on the right side of the root, then we can build our binary tree shape.         Then the rest of the preorder traversal is BDFGHIE, preorder is FDHGIBE, B is our new "root", derived from a preorder traversal FDHGI to the left of B, E B on the right, and continue to build         it the remaining pre-order traversal is DFGHI, preorder is FDHGI, D is our new "root", derived from a preorder traversal F on the left side of the D, HGI D on the right, and continue to build         then the rest the preorder traversal is GHI, preorder as HGI, G is our new "root", derived from a preorder traversal of the left side of H in G, I G on the right, and continue to build example 2:     known in order traversal of a binary tree FDHGIBEAC, postorder traversal of FHIGDEBCA, Fengyun restore binary tree.     Problem-solving ideas:         from the post-order traversal, we identified the root node A, derived from FDEBC in order traversal of the root node in the left, C on the right side of the root, then we can build our binary tree prototype.         And the preamble and in order to restore the binary tree, we can restore the binary tree by the same token in order and post-order.
    
         
        

        
          
        

        
            

             
    
    


    


There are light preorder traversal and post-order traversal of a binary tree can not be restored.

Guess you like

Origin www.cnblogs.com/ikaros-521/p/11224495.html