1
votes

I have a tree like this: enter image description here

If I do an in-order tree traversal on this tree would the output be:

d, h, b...

or

d, b, h...

In other words sense in-order tree traversal goes left -> root -> right, what happens when the leftmost node has a right child?

My guess is that in-order operates on subtrees and if we take d as the root of the leftmost subtree then the output should be

d, h, b...

Am I thinking about this correctly?

2

2 Answers

1
votes

Yes, you are right, d,h,b,... is the correct order. Easy to see, because both d and h are in the left subtree of b and must therefore come before b.

1
votes

Here is the order in which the sub-trees are going to be visited in the in-order traversal for the example tree, with a few added nodes to make it clearer (first a left subtree of a node, then the node itself, then the right subtree, in that order, for any node):

enter image description here

As we can see, the order of visit is d,h,b.