Given a binary tree, print even positioned nodes of even level in level order traversal. The root is considered at level 0, and the left most node of any level is considered as a node at position 0.
Input: 1 / \ 2 3 / \ \ 4 5 6 / \ 7 8 / \ 9 10 Output: 1 4 6 9 Input: 2 / \ 4 15 / / 45 17 Output: 2 45
Approach: To print nodes level by level, use level order traversal. The idea is based on Print level order traversal line by line. For that, traverse nodes level by level and switch even level flag after every level. Similarly, mark 1st node in every level as even position and switch it after each time the next node is processed.
Below is the implementation of the above approach:
1 4 6 10
- Print extreme nodes of each level of Binary Tree in alternate order
- Recursive Program to Print extreme nodes of each level of Binary Tree in alternate order
- Print all nodes between two given levels in Binary Tree
- Print Levels of all nodes in a Binary Tree
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Print Binary Tree levels in sorted order | Set 2 (Using set)
- Print Binary Tree levels in sorted order
- Print a Binary Tree in Vertical Order | Set 3 (Using Level Order Traversal)
- Print nodes between two given level numbers of a binary tree
- Print all the nodes except the leftmost node in every level of the given binary tree
- Print the nodes at odd levels of a tree
- Difference between sums of odd level and even level nodes of a Binary Tree
- Maximum sum of non-leaf nodes among all levels of the given binary tree
- Maximum sum of leaf nodes among all levels of the given binary tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
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.