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)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sum of nodes in the left view of the given binary tree
- Print Left View of a Binary Tree
- Iterative Method To Print Left View of a Binary Tree
- Check if a binary tree is sorted level-wise or not
- Check if value exists in level-order sorted complete binary tree
- Sum of nodes in the right view of the given binary tree
- Right view of Binary Tree using Queue
- Print Right View of a Binary Tree
- Bottom View of a Binary Tree
- Sum of nodes in top view of binary tree
- Bottom View of a Binary Tree using Recursion
- Print Bottom-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
- Print nodes in top view of Binary Tree | Set 2
- Sum of nodes in bottom view of Binary Tree
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Left-Child Right-Sibling Representation of Tree
- Get maximum left node in binary tree
- Convert left-right representation of a binary tree to down-right
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.
Improved By : GauravRajput1