Given the binary tree and you have to find out the n-th node of inorder traversal.
Input : n = 4 10 / \ 20 30 / \ 40 50 Output : 10 Inorder Traversal is : 40 20 50 10 30 Input : n = 3 7 / \ 2 3 / \ 8 5 Output : 8 Inorder: 2 7 8 3 5 3th node is 8
We do simple Inorder Traversal. While doing the traversal, we keep track of count of nodes visited so far. When count becomes n, we print the node.
Below is the implementation of above approach.
Time Complexity: O(n)
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.
- Find all possible binary trees with given Inorder Traversal
- Inorder Tree Traversal without Recursion
- Inorder Tree Traversal without recursion and without stack!
- Construct Special Binary Tree from given Inorder traversal
- Print Postorder traversal from given Inorder and Preorder traversals
- Inorder Non-threaded Binary Tree Traversal without Recursion or Stack
- Cartesian tree from inorder traversal | Segment Tree
- Calculate height of Binary Tree using Inorder and Level Order Traversal
- Inorder traversal of an N-ary Tree
- Check if Inorder traversal of a Binary Tree is palindrome 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 Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Level order traversal of Binary Tree using Morris Traversal
- Find n-th node in Preorder traversal of a Binary Tree
- Find n-th node in Postorder traversal of a Binary Tree
- Find the Kth node in the DFS traversal of a given subtree in a Tree
- Find the kth node in vertical order traversal of a Binary Tree
- Find Leftmost and Rightmost node of BST from its given preorder traversal
- Find parent of given node in a Binary Tree with given postorder traversal
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.