I recently came across a question. The question stated that a max heap is implemented using a 3-ary tree. Print the inorder traversal. I am confused whether it is left-child, parent, 2nd child , right child or left-child, 2nd child, parent, right child. Which one is it?
Asked
Active
Viewed 1,580 times
2
-
See https://en.wikipedia.org/wiki/Tree_traversal – KarelHusa Aug 25 '17 at 07:56
-
This page gives traversal only for binary tree. I want it for a 3nary tree – chiru player Aug 25 '17 at 09:26
-
Is that the entire question? "Print the inorder traversal of a 3-ary tree?" Depth-first traversal of an n-ary heap is kind of uncommon because the output is pretty much meaningless. A breadth-first traversal provides more meaningful information. But if you want to do "inorder", you get to define the order in which child nodes are visited. – Jim Mischel Aug 26 '17 at 14:37
-
This question was asked in a company recruitment test. A tree 3nary tree was given. Question was what is the inorder traversal. 4 options followed. – chiru player Aug 27 '17 at 10:56
1 Answers
0
You need to define the left and right part of the node children, depending on the problem you solve. Both of your suggestions are possible.
See more at: In-order tree traversal for non-binary trees

KarelHusa
- 1,995
- 18
- 26