Given a Binary Tree, print it’s left view. Left view of a Binary Tree is a set of nodes visible when tree is seen from the left side .
Input : 1 / \ 2 3 / \ / \ 4 5 6 7 Output : 1 2 4 Input : 1 / \ 2 3 \ / 4 5 \ 6 / \ 7 8 Output : 1 2 4 6 7
We have already discussed this problem using the Recursion method, here iterative approach is used to solve the above problem.
The idea is to do level order traversal of the Tree using a queue and print the first node at each level.
While doing level order traversal, after traversing all node at each level, push a NULL delimiter to mark the end of the current level. So, do the level order traversal of the tree. Print the first node at each level in the tree and push the children of all nodes at each level in the queue until a NULL delimiter is encountered.
Below is the implementation of above approach:
10 12 4 6 18
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.
- Print All Leaf Nodes of a Binary Tree from left to right | Set-2 ( Iterative Approach )
- Print Left View of a Binary Tree
- Deepest left leaf node in a binary tree | iterative approach
- Sum of nodes in the left view of the given binary tree
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- Check if the Left View of the given tree is sorted or not
- Print Right View of a Binary Tree
- Print Nodes in Top View of Binary Tree
- Print nodes in top view of Binary Tree | Set 2
- Print nodes in the Top View of Binary Tree | Set 3
- Print Bottom-Right View of a Binary Tree
- Print leaf nodes in binary tree from left to right using one stack
- Print all leaf nodes of a binary tree from right to left
- Print left and right leaf nodes separately in Binary Tree
- Print all leaf nodes of a Binary Tree from left to right
- Iterative Method to find Height of Binary Tree
- Iterative method to find ancestors of a given binary tree
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Check whether a given Binary Tree is Complete or not | Set 1 (Iterative Solution)
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.