Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,167 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,893 people online right now. Registration is fast and FREE... Join Now!




binary search tree

 
Reply to this topicStart new topic

binary search tree

ganjakh0r
3 Dec, 2007 - 11:46 PM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 2


My Contributions
Say you are given a list of keys K_1, K_2, K_3, ... , K_n and told that these are the keys returned, in that order, by a postorder traversal of a binary search tree.

Can you can reconstruct the tree by reading the list left-to-right exactly once ?

(As you go you can use the keys read so far to maintain a provisional tree. When you read the next item in the postorder traversal, you incorporate it into your provisional tree, changing/adding no more than a constant number of edges/pointers in the tree. When you have done this with the last key, you have reconstructed the tree.)

Any help would be highly appreciated.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Binary Search Tree
4 Dec, 2007 - 12:42 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
Moved to other languages, because it is not Java specific, so you might get more answers here.
User is offlineProfile CardPM
+Quote Post

skaoth
RE: Binary Search Tree
4 Dec, 2007 - 01:53 PM
Post #3

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 342



Thanked: 10 times
Dream Kudos: 100
My Contributions
Are there any other attributes on the BST? Like that this is a complete tree, or can it be de-generate?
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:14AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month