Construct Binary Tree from Preorder and Inorder TraversalSep 30 '12
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
Analysis
You may assume that duplicates do not exist in the tree.
1. Get an element from the preorder vector
2. Lookup the position of that element in the inorder vector
3. Using that position partition the inorder vector and recursively form the left and right subtrees using these partitions by doing 1 through 3 for every next element in the preorder vector
Rebel King is back!
ReplyDeleteNo Leetcode is back!
ReplyDelete