Given a Binary tree, find out depth of the deepest odd level leaf node. Take root level as depth 1.
Output : 5 Input : 10 / \ 28 13 / \ 14 15 / \ 23 24 Output : 3
We can traverse the tree starting from the root level and keep curr_level of the node.
Increment the curr_level each time we go to left or a right subtree.
Return the max depth of an odd level,if it exists.
1) return 0 if curr_node == NULL 2) if curr_node is leaf and curr_level is odd, return curr_level 3) else maximum(depthOdd(left subtree), depthOdd(right subtree))
Below is the implementation.
This article is contributed by Shubham Gupta. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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 depth of the deepest odd level leaf node
- Deepest left leaf node in a binary tree
- Deepest right leaf node in a binary tree | Iterative approach
- Find the Deepest Node in a Binary Tree Using Queue STL - SET 2
- Find the Deepest Node in a Binary Tree
- Deepest left leaf node in a binary tree | iterative approach
- Difference between sums of odd level and even level nodes of a Binary Tree
- Count nodes from all lower levels smaller than minimum valued node of current level for every level in a Binary Tree
- Print odd positioned nodes of odd levels in level order of the given binary tree
- Difference between sums of odd level and even level nodes in an N-ary Tree
- Replace node with depth in a binary tree
- Print nodes of a Binary Search Tree in Top Level Order and Reversed Bottom Level Order alternately
- Print the nodes corresponding to the level value for each level of a Binary Tree
- Replace every node with depth in N-ary Generic Tree
- Minimum valued node having maximum depth in an N-ary Tree
- Difference between sums of odd position and even position nodes for each level of a Binary Tree
- Print even positioned nodes of odd levels in level order of the given binary tree
- Print odd positioned nodes of even levels in level order of the given binary tree
- Find Minimum Depth of a Binary Tree
- Calculate depth of a full Binary tree from Preorder