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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Check if Inorder traversal of a Binary Tree is palindrome or not
- 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
- Level order traversal of Binary Tree using Morris Traversal
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Tree Traversals (Inorder, Preorder and Postorder)
- Construct Tree from given Inorder and Preorder traversals
- Construct a Binary Tree from Postorder and Inorder
- Inorder Successor of a node in Binary Tree
- Print K inorder successors of a Binary Tree in O(1) space
- Check if given Preorder, Inorder and Postorder traversals are of same tree
- 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.