Given an N-ary tree containing, the task is to print the inorder traversal of the tree.
Input: N = 3
Output: 5 6 2 7 3 1 4
Input: N = 3
Output: 2 5 3 1 4 6
Approach: The inorder traversal of an N-ary tree is defined as visiting all the children except the last then the root and finally the last child recursively.
- Recursively visit the first child.
- Recursively visit the second child.
- Recursively visit the second last child.
- Print the data in the node.
- Recursively visit the last child.
- Repeat the above steps till all the nodes are visited.
Below is the implementation of the above approach:
5 6 2 7 3 1 4
- Cartesian tree from inorder traversal | Segment Tree
- Inorder Tree Traversal without Recursion
- Inorder Tree Traversal without recursion and without stack!
- Construct Special Binary Tree from given Inorder traversal
- Inorder Non-threaded Binary Tree Traversal without Recursion or Stack
- Calculate height of Binary Tree using Inorder and Level Order Traversal
- Find n-th node of inorder traversal
- Find all possible binary trees with given Inorder Traversal
- Print Postorder traversal from given Inorder and Preorder traversals
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Inorder Successor of a node in Binary Tree
- Construct Tree from given Inorder and Preorder traversals
- Tree Traversals (Inorder, Preorder and Postorder)
- Construct a Binary Tree from Postorder and Inorder
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.