BST Problem
4 posters
Page 1 of 1
BST Problem
You are given the post order traversal,P, of a BST on n elements 1,2,...,n.You have to determine the unique BST tht hasP as its POST ORDER TRAVERSAL.what is the time complexity of the most effecient algorithm for doing this.
shivang- Posts : 42
Join date : 2009-01-30
Age : 35
@shivang
n logn for sorting and getting the in order
another logn for making the tree itself from in order and postorder
another logn for making the tree itself from in order and postorder
ballu- Posts : 58
Join date : 2009-02-01
@ballu
u can make the BST with the use of only postorder also.....
there is another answer......
there is another answer......
shivang- Posts : 42
Join date : 2009-01-30
Age : 35
@shivang
bhai ab answer to bata do ..,..kafi time ho gaya post ko..
$corpion- Posts : 25
Join date : 2009-01-30
Age : 37
Re: BST Problem
Step 1. The last node in the post order listing will be the root.
Step 2. Now start from the beginning to the point where the values are less than root.
Step 3. In this new list, the last element will be immediate left child of root.
Step 4. Continue with the new list thus formed.
Step 5. If ( value < root) then left child
................else right child
Step 6. In this way you will build your left subtree of the BST in question.
Repeat this procedure for the Right subtree of the BST. complexity O(nlogn)
Step 2. Now start from the beginning to the point where the values are less than root.
Step 3. In this new list, the last element will be immediate left child of root.
Step 4. Continue with the new list thus formed.
Step 5. If ( value < root) then left child
................else right child
Step 6. In this way you will build your left subtree of the BST in question.
Repeat this procedure for the Right subtree of the BST. complexity O(nlogn)
Beagle- Posts : 40
Join date : 2009-01-30
Similar topics
» from ACM modified first problem:Bansal Sir
» Graph Bipartite problem
» Mayor Problem; universal sink
» Graph Bipartite problem
» Mayor Problem; universal sink
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|