# Types of Binary trees

## Introduction

A binary tree consists of a finite number of nodes, either empty or having a root, and two disjoint binary trees called left and right subtree. A binary tree node is made of a left pointer, a right pointer, and a data element.

There are mainly five types of Binary Trees frequently used. But sometimes, their names turn out confusing to identify distinctly. In this article, we will understand their unique properties and how they are different from each other through examples.

## Types

Frequently used these types are -

1. Full or Strict Binary Tree
2. Complete Binary Tree
3. Perfect Binary Tree
4. Degenerate Binary Tree
5. Balanced Binary Tree

## Full or Strict Binary Tree

Binary tree in which every node contains zero or two children nodes. In other words, the binary tree with all nodes having two children except leaf nodes.

Let’s visualize Full Binary Tree through examples

## Complete Binary Tree

In this type of binary tree, all levels except the last level must be completely filled. In the last level, all nodes must be as left as possible.

Let’s visualize Complete Binary Tree through examples

## Perfect Binary Tree

Binary tree in which all internal nodes have two children and all leaf nodes are at the same level (i.e., last level).

Let’s visualize this type of Binary Tree through example

So, all perfect binary trees are full as well as complete binary trees but not vice versa.

## Degenerate Binary Tree

If each internal node has only one child node in a binary tree, it is called a Degenerate Binary tree.

Let’s visualize this type of binary tree through examples.

## Balanced Binary Tree

If in a binary tree, the height of the left subtree and right subtree differ by at most 1, then it is a Balanced  Binary Tree.

AVL tree and Red-Black Tree come under the balanced binary tree.

Let’s visualize this type of binary tree through examples.

## FAQs

1. What are the different types of traversals in Binary Trees?
Three are mainly three types of traversal techniques in Binary Trees.
Inorder
Preorder
Postorder

2. What are Binary Trees?
A tree is called a binary tree if every node has at most two children nodes.  A binary tree node constitutes a left pointer, a right pointer, and a data element. An empty binary tree (with zero nodes) is also a valid binary tree.

3. What are some of the advantages of using binary trees?
Insertion and deletion of data are faster than linked lists and arrays.
A hierarchical way of storing dataAccessing data is faster than a linked listIt also signifies the structural relationship existing in the given data.

4. What is a Perfect Binary Tree?
Binary tree in which all internal nodes have two children and all leaf nodes are at the same level (i.e., last level).

5. What is the need for balancing Binary Trees?
A balanced binary tree optimizes search time in the tree.
Search time complexity in a balanced binary tree is O(log n) in the worst case, but for an unbalanced tree, it is O(n), where n is the number of nodes. So maintaining a balanced tree is beneficial for large trees.

## Key Takeaways

In this article, we have explored various types of binary trees and how they are different from each other.

Side by side, we should also learn about insertion, searching, and deletion operations in  Binary trees.

You can practice these concepts along with a wide range of coding questions commonly asked in interviews in CodeStudio. Along with coding questions, we can also find the interview experience of scholars working in renowned product-based companies here.

Happy learning! 