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$\text{SQPTRWUV}$$\text{SQPTUWRV}$$\text{SQPTWUVR}$$\text{SQPTRUWV}$ Data Structures gatecse-2014-set3 data-structures tree easy + – go_editor 26.1k views answer comment Share Follow Print See all 12 Comments 12 12 Comments reply Show 9 previous comments samir757 commented Dec 25, 2021 reply Follow flag For detailed explanation of the question , refer to the video below https://www.youtube.com/watch?v=XjggSKsOoes 6 6 replyShare Shaikh727 commented Jul 29, 2022 reply Follow flag Thank you 0 0 replyShare Bit_by_Bit commented Nov 5, 2025 reply Follow flag AssumingAny representation needs to be consistent, and our biggest helpers are Q-S and U-W, By consistent I mean if in Q-S( we assume S to be left child of Q) then in U-W(W must also be left child of U).So we boil down to three possibilities here, either be left child(L), middle child(M) or Right child(R). Preorder -> Root->Left->Middle->RightPostorder-> Left->Middle->Right->RootInorder there isn't any standard So Left->Root->Middle->Right Left->Middle->Root->Right 2 2 replyShare Please log in or register to add a comment.
Best answer 70 70 votes Correct Option: A The inorder traversal order of a ternary tree is left $\rightarrow $ root $\rightarrow $ middle $\rightarrow $ right. Gate Keeda answered Oct 8, 2014 • edited May 5, 2021 by soujanyareddy13 Gate Keeda comment Share Follow See all 16 Comments 16 16 Comments reply Show 13 previous comments sudo commented Aug 12, 2024 reply Follow flag @Lakshman Bhaiya how we are taking W as the left subtree of U any specific reason. If we take W as right subtree of U answer is coming ( D ) correct me if i am wrong 0 0 replyShare Lakshman Bhaiya commented Aug 12, 2024 i edited by Lakshman Bhaiya Aug 12, 2024 reply Follow flag It's not a binary tree it's a ternary tree, so we don't have a specific rule. See this: https://cs.stackexchange.com/questions/98891/inorder-traversal-of-the-ternary-tree 5 5 replyShare saket jaiswal commented Mar 26, 2025 reply Follow flag this kind of question do we get bonus marks 1 1 replyShare Please log in or register to add a comment.
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'. Samujjal Das answered Dec 2, 2016 Samujjal Das comment Share Follow See all 2 Comments 2 2 Comments reply Sonali Rangwani commented Dec 14, 2016 reply Follow flag Here order will not start from S as well. It will start from Q because S is the middle element which will come after root element Q. 2 2 replyShare Prateek K commented Jan 7, 2019 reply Follow flag I think the examiner designed the option to suggest that, if a node has only one child, then it left child. Therefore, S comes before Q and W comes before U in inorder traversal of the given tree. 1 1 replyShare Please log in or register to add a comment.
16 16 votes For inorder traversal you can take a trick whenever you visit the node second time take it into inorder sequence.. :D Ankit Srivastava 7 answered Oct 14, 2017 Ankit Srivastava 7 comment Share Follow See all 11 Comments 11 11 Comments reply Show 8 previous comments Sambhrant Maurya commented Nov 24, 2019 reply Follow flag @Lakshman Patel RJIT Can you tell what will the the preorder and postorder of this tree? 1 1 replyShare Lakshman Bhaiya commented Nov 24, 2019 i edited by Lakshman Bhaiya Nov 24, 2019 reply Follow flag @Sambhrant Maurya see this 1 2 0 0 replyShare Vishal_kumar98 commented Oct 26, 2020 reply Follow flag You should check out RBR videos on this topic. You will never miss one question from here. 0 0 replyShare Please log in or register to add a comment.
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) ambikesh answered Dec 8, 2017 ambikesh comment Share Follow See 1 comment 1 1 comment reply ANIRUDDHA SINGH commented May 4, 2023 reply Follow flag “The inorder traversal of a ternary tree is given by Left > Root > Middle > Right.”” Ok this is general for this. What if question is about Post and pre traversal , are they pre: root-middle-left-right post :left-right-root-middle Someone conform it? How it will go for other trversal 0 0 replyShare Please log in or register to add a comment.
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) Nitesh Singh 2 answered Jan 18, 2019 Nitesh Singh 2 comment Share Follow See all 2 Comments 2 2 Comments reply Sambhrant Maurya commented Nov 24, 2019 reply Follow flag Will the preorder and postorder traversal of a ternary tree be: Pre: Root, Left, Mid, Right Post: Left, Mid, Right, Root ?? 0 0 replyShare Pranavpurkar commented Jul 27, 2022 reply Follow flag Sambhrant Maurya I think yes!! the change is only in the inorder traversals. 0 0 replyShare Please log in or register to add a comment.
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). vaibhavkedia968 answered Sep 4, 2020 vaibhavkedia968 comment Share Follow 0 reply Please log in or register to add a comment.