• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 04, 2022 |130 Views
Find if given vertical level of binary tree is sorted or not
Description
Discussion

A simple solution is to first do level order traversal of the binary tree and store each vertical level in different arrays. After this check, if array corresponding to level l is sorted or not. This solution has large memory requirements that can be reduced.

A efficient solution is to do vertical level order traversal of the binary tree and keep track of node values in vertical level l of the binary tree. A sequence is sorted if the previous element is less than or equal to the current element. While doing vertical level order traversal store previous value and compare current node in vertical level l with this previous value of level l.


Find if given vertical level of binary tree is sorted or not : https://www.geeksforgeeks.org/find-given-vertical-level-binary-tree-sorted-not/

Read More