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 3 5 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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Cartesian tree from inorder traversal | Segment Tree
- Inorder Tree Traversal without Recursion
- 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
- Check if Inorder traversal of a Binary Tree is palindrome or not
- Inorder Tree Traversal without recursion and without stack!
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Print Postorder traversal from given Inorder and Preorder traversals
- Find all possible binary trees with given Inorder Traversal
- Find n-th node of inorder traversal
- Level order traversal of Binary Tree using Morris Traversal
- Tree Traversals (Inorder, Preorder and Postorder)
- Construct Tree from given Inorder and Preorder traversals
- Construct a tree from Inorder and Level order traversals | Set 1
- Check if an array represents Inorder of Binary Search tree or not
- Replace each node in binary tree with the sum of its inorder predecessor and successor
- Inorder Successor of a node in Binary Tree
- Construct a tree from Inorder and Level order traversals | Set 2
- Check if given Preorder, Inorder and Postorder traversals are of same tree | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.