Given a Binary Tree check whether it is skewed binary tree or not. A skewed tree is a tree where each node has only one child node or none.
Input : 5 / 4 \ 3 / 2 Output : Yes Input : 5 / 4 \ 3 / \ 2 4 Output : No
The idea is to check if a node has two children. If node has two children return false, else recursively compute whether subtree with one child is skewed tree. If node is leaf node return true.
Below is the implementation of above approach:
1 1 0
Time complexity of this solution is
Best case : O(1) when root has two children.
Worst case : O(h) when tree is skewed tree.
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.
- Convert a Binary Search Tree into a Skewed tree in increasing or decreasing order
- Skewed Binary Tree
- Ways to color a skewed tree such that parent and child have different colors
- Check whether a binary tree is a full binary tree or not
- Check whether a binary tree is a full binary tree or not | Iterative Approach
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Check whether a given Binary Tree is Complete or not | Set 1 (Iterative Solution)
- Check whether a given binary tree is perfect or not
- Check whether a node is leaf node or not for multiple queries
- Check whether BST contains Dead End or not
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Check whether every node of binary tree has a value K on itself or its any immediate neighbours
- Check if a Binary Tree is an Even-Odd Tree or not
- Queries to check whether a given digit is present in the given Range
- Find whether it is possible to finish all tasks or not from given dependencies
- A program to check if a binary tree is BST or not
- Check if an array represents Inorder of Binary Search tree or not
- Check if a binary tree is sorted level-wise or not
- Check if Inorder traversal of a Binary Tree is palindrome or not
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.