Given a binary tree, print all nodes will are full nodes. Full Nodes are nodes which has both left and right children as non-empty.
Input : 10 / \ 8 2 / \ / 3 5 7 Output : 10 8 Input : 1 / \ 2 3 / \ 4 6 Output : 1 3
This is a simple problem. We do any of the traversals (Inorder, Preorder, Postorder, level order traversal) and keep printing nodes that have mode left and right children as non-NULL.
Time Complexity : O(n)
This article is contributed by Rakesh Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.
- Check whether a binary tree is a full binary tree or not
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Count full nodes in a Binary tree (Iterative and Recursive)
- Print all nodes in a binary tree having K leaves
- Print all internal nodes of a Binary tree
- Print Levels of all nodes in a Binary Tree
- Print all even nodes of Binary Search Tree
- Print Sum and Product of all Non-Leaf nodes in Binary Tree
- Print all nodes between two given levels in Binary Tree
- Print All Leaf Nodes of a Binary Tree from left to right | Set-2 ( Iterative Approach )
- Print all leaf nodes of a binary tree from right to left
- Print path from root to all nodes in a Complete Binary Tree
- Print all the nodes except the leftmost node in every level of the given binary tree
- Print all nodes except rightmost node of every level of the Binary Tree
- Print alternate nodes from all levels of a Binary Tree
- Print all leaf nodes of a Binary Tree from left to right
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Count the nodes of the tree which make a pangram when concatenated with the sub-tree nodes
- Count of all prime weight nodes between given nodes in the given Tree
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree