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
- 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
- Ways to color a skewed tree such that parent and child have different colors
- 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 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 whether BST contains Dead End or not
- Check whether a node is leaf node or not for multiple queries
- 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
- Check if a binary tree is subtree of another binary tree | Set 1
- Check if a binary tree is subtree of another binary tree | Set 2
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- 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 (not BST) has duplicate values
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.