Given a Binary Tree, find the deepest leaf node that is left child of its parent. For example, consider the following tree. The deepest left leaf node is the node with value 9.
1 / \ 2 3 / / \ 4 5 6 \ \ 7 8 / \ 9 10
The idea is to recursively traverse the given binary tree and while traversing, maintain “level” which will store the current node’s level in the tree. If current node is left leaf, then check if its level is more than the level of deepest left leaf seen so far. If level is more then update the result. If current node is not leaf, then recursively find maximum depth in left and right subtrees, and return maximum of the two depths. Thanks to Coder011 for suggesting this approach.
The deepest left child is 9
Time Complexity: The function does a simple traversal of the tree, so the complexity is O(n).
This article is contributed by Abhay Rathi. 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.
- Deepest left leaf node in a binary tree | iterative approach
- Deepest right leaf node in a binary tree | Iterative approach
- Find the Deepest Node in a Binary Tree
- Depth of the deepest odd level node in Binary Tree
- Find the Deepest Node in a Binary Tree Using Queue STL - SET 2
- Print all leaf nodes of a Binary Tree from left to right
- Print all leaf nodes of a binary tree from right to left
- Print left and right leaf nodes separately in Binary Tree
- Print leaf nodes in binary tree from left to right using one stack
- Print All Leaf Nodes of a Binary Tree from left to right | Set-2 ( Iterative Approach )
- Find depth of the deepest odd level leaf node
- Delete the last leaf node in a Binary Tree
- Closest leaf to a given node in Binary Tree
- Print the nodes of binary tree as they become the leaf node
- Get maximum left node in binary tree
- Create a binary tree from post order traversal and leaf node array
- Change a Binary Tree so that every node stores sum of all nodes in left subtree
- Print the longest leaf to leaf path in a Binary tree
- Queries to find sum of distance of a given node to every leaf node in a Weighted Tree
- Construct XOR tree by Given leaf nodes of Perfect Binary Tree
Improved By : shrikanth13