mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

BST Problem

4 posters

Go down

BST Problem Empty BST Problem

Post  shivang Thu Feb 12, 2009 3:27 pm

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
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

BST Problem Empty @shivang

Post  ballu Thu Feb 12, 2009 4:13 pm

n logn for sorting and getting the in order
another logn for making the tree itself from in order and postorder
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

BST Problem Empty @ballu

Post  shivang Thu Feb 12, 2009 4:54 pm

u can make the BST with the use of only postorder also.....
there is another answer......
shivang
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

BST Problem Empty @shivang

Post  $corpion Tue Feb 17, 2009 7:52 pm

bhai ab answer to bata do ..,..kafi time ho gaya post ko..
$corpion
$corpion

Posts : 25
Join date : 2009-01-30
Age : 37

Back to top Go down

BST Problem Empty Re: BST Problem

Post  Beagle Thu Feb 19, 2009 12:34 pm

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)

Beagle

Posts : 40
Join date : 2009-01-30

Back to top Go down

BST Problem Empty Re: BST Problem

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum