-2

In-order traversal: 24,17,32,18,51,11,26,39,43
Pre-order traversal: 11,32,24,17,51,18,43,26,39

The question asked to find which nodes belong on the right subtree of the root node. I am having trouble constructing the tree based on the 2 traversal methods..

Would greatly appreciate some help on this.

asked Apr 3, 2022 at 17:47
9
  • Have a look at this blog post. Commented Apr 3, 2022 at 17:50
  • You can't, in general, determine the full tree from just one type of traversal. And your tree does not produce the pre-order traversal you started with. Commented Apr 3, 2022 at 17:52
  • I think you confuse binary tree with binary search tree. A search tree has an additional condition left < root < right which a binary tree does not have. Commented Apr 3, 2022 at 17:56
  • Oh crap you're right I did not read the question clearly... Thanks for your help!! Commented Apr 3, 2022 at 18:00
  • 1
    Ok the nodes which belong to the right subtree of the root node would be 43, 26, 39. Is this correct? Commented Apr 3, 2022 at 18:07

1 Answer 1

0

The tree that is defined by those two traversals is:

 __ 11 __
 / \
 _ 32 _ 43
 / \ /
24 51 26
 \ / \
 17 18 39
 

The procedure to build this, is described in this Q&A

answered Apr 4, 2022 at 4:29
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.