Hey,
I am having trouble with a question on a sample exam in a programming class I am in.
Describe (in a sentence or two) all binary trees whose nodes appear in exactly the same sequence in both (i) preorder and inorder, (ii) preorder and postorder, (iii) inorder and postorder.
That's the question. I know how to traverse the tree in preorder, inorder, and postorder. Aswell as level order. But, I am unsure how to determine what BSTs would traverse the same in the way listed.
Thanks.
3 replies to this topic
#1
Posted 02 April 2011 - 01:11 PM
|
|
|
#2
Posted 04 April 2011 - 07:24 AM
I. Preorder and inorder both process the root before the right subtree, so trees that appear the same would be trees whose nodes only have right subtrees.
II. Preorder and postorder each process the root at a different time in relation to both subtrees, so trees that appear the same would be trees with one node and no subtrees.
III. Inorder and postorder both process the left subtree before the root, so trees that appear the same would be trees whose nodes only have left subtrees.
II. Preorder and postorder each process the root at a different time in relation to both subtrees, so trees that appear the same would be trees with one node and no subtrees.
III. Inorder and postorder both process the left subtree before the root, so trees that appear the same would be trees whose nodes only have left subtrees.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 04 April 2011 - 12:15 PM
Great! Thanks a lot gregwarner, that's a really big help!!!
#4
Posted 14 July 2011 - 06:52 AM
Following would be interesting related problems along with code for traversal of BST
http://forum.codecal...if-bst-not.html
http://forum.codecal...cestor-bst.html
http://forum.codecal...if-bst-not.html
http://forum.codecal...cestor-bst.html
Today is the first day of the rest of my life
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









