# Skewed Binary Tree

A skewed binary tree is a type of binary tree in which all the nodes have only either one child or no child.

Types of Skewed Binary trees
There are 2 special types of skewed tree:

1. Left Skewed Binary Tree:
These are those skewed binary trees in which all the nodes are having a left child or no child at all. It is a left side dominated tree. All the right children remain as null.

Below is an example of a left-skewed tree:

 `#include ` `using` `namespace` `std; ` ` `  `// A Tree node ` `struct` `Node { ` `    ``int` `key; ` `    ``struct` `Node *left, *right; ` `}; ` ` `  `// Utility function to create a new node ` `Node* newNode(``int` `key) ` `{ ` `    ``Node* temp = ``new` `Node; ` `    ``temp->key = key; ` `    ``temp->left = temp->right = NULL; ` ` `  `    ``return` `(temp); ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``/* ` `            ``1 ` `           ``/ ` `          ``2 ` `         ``/ ` `        ``3 ` `    ``*/` `    ``Node* root = newNode(1); ` `    ``root->left = newNode(2); ` `    ``root->left->left = newNode(3); ` ` `  `    ``return` `0; ` `} `

 `// Java implementation of above approach ` `import` `java.util.*; ` ` `  `class` `GFG ` `{ ` `     `  `// A Tree node ` `static` `class` `Node  ` `{ ` `    ``int` `key; ` `     ``Node left, right; ` `}; ` `   `  `// Utility function to create a new node ` `static` `Node newNode(``int` `key) ` `{ ` `    ``Node temp = ``new` `Node(); ` `    ``temp.key = key; ` `    ``temp.left = temp.right = ``null``; ` `   `  `    ``return` `(temp); ` `} ` `   `  `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` `    ``/* ` `            ``1 ` `           ``/ ` `          ``2 ` `         ``/ ` `        ``3 ` `    ``*/` `    ``Node root = newNode(``1``); ` `    ``root.left = newNode(``2``); ` `    ``root.left.left = newNode(``3``); ` `} ` `} ` ` `  `// This code is contributed by Arnab Kundu `

 `# Python3 implementation of the above approach  ` ` `  `# Class that represents an individual ` `# node in a Binary Tree  ` `class` `Node:  ` `    ``def` `__init__(``self``, key):  ` `         `  `        ``self``.left ``=` `None` `        ``self``.right ``=` `None` `        ``self``.val ``=` `key  ` `         `  `# Driver code ` ` `  `"""         1 ` `           ``/ ` `          ``2 ` `         ``/ ` `        ``3     """` `root ``=` `Node(``1``) ` `root.left ``=` `Node(``2``) ` `root.left.left ``=` `Node(``2``) ` ` `  `# This code is contributed by dhruvsantoshwar `

 `// C# implementation of above approach  ` `using` `System; ` `  `  `class` `GFG  ` `{  ` `          `  `    ``// A Tree node  ` `     ``public` `class` `Node  ` `    ``{  ` `         ``public` `int` `key;  ` `         ``public` `Node left, right;  ` `    ``};  ` `          `  `    ``// Utility function to create a new node  ` `     ``static` `Node newNode(``int` `key)  ` `    ``{  ` `        ``Node temp = ``new` `Node();  ` `        ``temp.key = key;  ` `        ``temp.left = temp.right = ``null``;  ` `          `  `        ``return` `(temp);  ` `    ``}  ` `          `  `    ``// Driver code  ` `    ``public` `static` `void` `Main()  ` `    ``{  ` `        ``/*  ` `                ``1  ` `            ``/  ` `            ``2  ` `            ``/  ` `            ``3  ` `        ``*/` `        ``Node root = newNode(1);  ` `        ``root.left = newNode(2);  ` `        ``root.left.left = newNode(3);  ` `    ``}  ` `} ` ` `  `// This code is contributed by AnkitRai01 `

2. Right Skewed Binary Tree:
These are those skewed binary trees in which all the nodes are having a right child or no child at all. It is a right side dominated tree. All the left children remain as null.

Below is an example of a right-skewed tree:

 `#include ` `using` `namespace` `std; ` ` `  `// A Tree node ` `struct` `Node { ` `    ``int` `key; ` `    ``struct` `Node *left, *right; ` `}; ` ` `  `// Utility function to create a new node ` `Node* newNode(``int` `key) ` `{ ` `    ``Node* temp = ``new` `Node; ` `    ``temp->key = key; ` `    ``temp->left = temp->right = NULL; ` ` `  `    ``return` `(temp); ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``/* ` `        ``1 ` `         ``\ ` `          ``2 ` `           ``\ ` `            ``3 ` `    ``*/` `    ``Node* root = newNode(1); ` `    ``root->right = newNode(2); ` `    ``root->right->right = newNode(3); ` ` `  `    ``return` `0; ` `} `

 `// Java implementation of above approach ` `import` `java.util.*; ` `class` `GFG ` `{ ` `     `  `// A Tree node ` `static` `class` `Node ` `{ ` `    ``int` `key; ` `    ``Node left, right; ` `}; ` `   `  `// Utility function to create a new node ` `static` `Node newNode(``int` `key) ` `{ ` `    ``Node temp = ``new` `Node(); ` `    ``temp.key = key; ` `    ``temp.left = temp.right = ``null``; ` `   `  `    ``return` `(temp); ` `} ` `   `  `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` `    ``/* ` `       ``1 ` `        ``\ ` `         ``2 ` `          ``\ ` `           ``3 ` `    ``*/` `    ``Node root = newNode(``1``); ` `    ``root.right = newNode(``2``); ` `    ``root.right.right = newNode(``3``); ` `} ` `} ` ` `  `// This code is contributed by Arnab Kundu `

 `// C# implementation of above approach ` `using` `System; ` `  `  `class` `GFG ` `{ ` `       `  `// A Tree node ` `public` `class` `Node ` `{ ` `    ``public` `int` `key; ` `    ``public` `Node left, right; ` `}; ` `     `  `// Utility function to create a new node ` `static` `Node newNode(``int` `key) ` `{ ` `    ``Node temp = ``new` `Node(); ` `    ``temp.key = key; ` `    ``temp.left = temp.right = ``null``; ` `     `  `    ``return` `(temp); ` `} ` `     `  `// Driver code ` `public` `static` `void` `Main(String []args) ` `{ ` `    ``/* ` `       ``1 ` `        ``\ ` `         ``2 ` `          ``\ ` `           ``3 ` `    ``*/` `    ``Node root = newNode(1); ` `    ``root.right = newNode(2); ` `    ``root.right.right = newNode(3); ` `} ` `} ` `  `  `// This code is contributed by PrinciRaj1992 `

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.

Im a final year MCA student at Panjab University, Chandigarh, one of the most prestigious university of India I am skilled in various aspects related to Web Development and AI I have worked as a freelancer at upwork and thus have knowledge on various aspects related to NLP, image processing and web

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.

Article Tags :
Practice Tags :