Given a binary tree. The task is to find the value of the deepest node in the given binary tree.
Input: Root of below tree 1 / \ 2 3 / \ / \ 4 5 6 7 \ 8 Output: 8 Input: Root of below tree 1 / \ 2 3 / 6 Output: 6
Approach: We have already discussed the two different ways to find the deepest node in a binary tree in this post. Here, we will find the deepest node in the tree using a queue data structure. We will first push the root into the queue and then we will push it’s child nodes after removing parent node from the queue. We will continue this process until the queue empty. The last node in the queue is the deepest node of the binary tree.
Below is the implementation of the 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 the Deepest Node in a Binary Tree
- Depth of the deepest odd level node in Binary Tree
- Deepest left leaf node in a binary tree
- Deepest right leaf node in a binary tree | Iterative approach
- Deepest left leaf node in a binary tree | iterative approach
- Find depth of the deepest odd level leaf node
- Find maximum and minimum element in binary tree without using recursion or stack or queue
- Find mirror of a given node in Binary tree
- Find the parent of a node in the given binary tree
- Find n-th node in Postorder traversal of a Binary Tree
- Find the node with minimum value in a Binary Search Tree
- Find distance from root to given node in a binary tree
- Find the maximum node at a given level in a binary tree
- Find the color of given node in an infinite binary tree
- Find the node with maximum value in a Binary Search Tree
- Find n-th node in Preorder traversal of a Binary Tree
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)
- Find parent of given node in a Binary Tree with given postorder traversal
- Find the kth node in vertical order traversal of a Binary Tree
- Find the node with minimum value in a Binary Search Tree using recursion
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.