edited by
26,148 views
65 65 votes

Consider the following rooted tree with the vertex labeled $P$ as the root:

The order in which the nodes are visited during an in-order traversal of the tree is

  1. $\text{SQPTRWUV}$
  2. $\text{SQPTUWRV}$
  3. $\text{SQPTWUVR}$
  4. $\text{SQPTRUWV}$

9 Answers

Best answer
70 70 votes

Correct Option: A

The inorder traversal order of a ternary tree is left $\rightarrow $ root $\rightarrow $ middle $\rightarrow $ right.

edited by
23 23 votes

The inorder traversal of a ternary tree is given by Left > Root > Middle > Right.

But if you apply this traversal sequence on this tree, the order is SQPTWURV.

According to the answer given by various books, the answer is (A).

(A) can only be the answer if we consider 'S' to be the left child of 'Q', and 'W' to be the left child of 'U'.

16 16 votes
For inorder traversal you can take a trick
whenever you visit the node second time take it into inorder sequence.. :D
5 5 votes
Inorder transversal of ternary tree is :- left -> Root->Middle->Right

from the given figure, it is not clear whether W is middle child of U or left child of U

if W is middle child of U then  SQPTRUWV (option D)

if W is left child of U then       SQPTRWUV  (option A)
1 1 vote
Inorder Traversal: Left, Root, Middle, Right.

If single child is given of a node then First child of the node is considered as the left child so here S becomes left child of Q.

so answer will be option (A)
1 1 vote

Since left subtree of P is giving SQ (note that all options start with SQ), middle subtree of R has to give WU (because structure is same). Also, knowing the algorithm of ternary inorder traversal (left →→ root →→ middle →→ right as mentioned in the best answer), we can conclude that both S and W are indeed the left child of Q and U respectively. This rules out option B and D. Option C is also ruled out because R cannot come at the end of an inorder when it is having its right child. So, only option A is left, which is the answer.

The thing is, you may know the algorithm for ternary inorder, but still the question can remain unclear, and then you have to come up with the answer using the options given (finding what is “common” among all the options).

Answer:
Position:
Show:

Related questions

9 9 votes
5 answers 5 answers
8.9k
8.9k views
go_editor asked Sep 28, 2014
8,861 views
In the context of modular software design, which one of the following combinations is desirable?High cohesion and high couplingHigh cohesion and low couplingLow cohesion ...
73 73 votes
11 answers 11 answers
32.1k
32.1k views
go_editor asked Sep 28, 2014
32,128 views
Consider the pseudocode given below. The function $DoSomething()$ takes as argument a pointer to the root of an arbitrary tree represented by the $leftMostChild-rightSibl...
81 81 votes
12 answers 12 answers
22.0k
22.0k views
go_editor asked Sep 28, 2014
22,026 views
Consider the C function given below. Assume that the array $listA$ contains $n (>0)$ elements, sorted in ascending order.int ProcessArray(int *listA, int x, int n) { in...
75 75 votes
10 answers 10 answers
27.0k
27.0k views
go_editor asked Sep 28, 2014
26,957 views
Consider the following relational schema:employee (empId,empName,empDept) customer (custId,custName,salesRepId,rating) salesRepId is a foreign key referring to empId of t...