Given a tree, our task is to check whether its left view is sorted or not. If it is then return true else false.
The left view for the tree would be 10, 20, 50 which is in sorted order.
To solve the problem mentioned above we have to perform level order traversal on the tree and look for the very first node of each level. Then initialize a variable to check whether its left view is sorted or not. If it is not sorted, then we can break the loop and print false else loop goes on and at last print true.
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.
- Sum of nodes in the left view of the given binary tree
- Iterative Method To Print Left View of a Binary Tree
- Print Left View of a Binary Tree
- Check if a binary tree is sorted level-wise or not
- Check whether a given binary tree is skewed binary tree or not?
- Find if given vertical level of binary tree is sorted or not
- Check if two sorted arrays can be merged to form a sorted array with no adjacent pair from the same array
- Sum of nodes in the right view of the given binary tree
- Check whether a given array is a k sorted array or not
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Check whether a binary tree is a full binary tree or not
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Check if a Binary Tree is an Even-Odd Tree or not
- Print Right View of a Binary Tree
- Print Nodes in Top View of Binary Tree
- Print nodes in the Top View of Binary Tree | Set 3
- Sum of nodes in top view of binary tree
- Print Bottom-Right View of a Binary Tree
- Sum of nodes in bottom view of Binary Tree
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : GauravRajput1