Table of contents
1.
Introduction
2.
Binary Trees
3.
Difference Between Normal Tree and a Binary Tree
4.
Complete Binary Tree
5.
Full Binary Tree
6.
Binary Expression Trees
7.
FAQs
8.
Key Takeaways
Last Updated: Mar 27, 2024

Binary Trees

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

When we are talking about data structures, the name that we cannot forget is Tree. The tree is a very important data structure, useful in all aspects of storing data in a hierarchical manner. When we talk about trees in detail, then the classification of trees is an important thing to discuss. For now, we will only discuss one classification of the tree, i.e., the Binary Tree.

This article will help us understand the Binary Tree and its properties. So let's start to enhance our knowledge about Binary Trees.

Binary Trees

A tree in which all the nodes do not have more than two children is called a Binary Tree. 

Example: 

An example of Binary Tree


Below are some terminologies related to Binary Tree:

  • Root Node: A Binary Tree consists of a unique node called the root node. The rest of the nodes are said to constitute its subtree. In fig 1, the node with value 3 is the root node, and other nodes constitute its subtree. 
     
  • Left Child: The node which is pointed by a node in its left is called its left child. In the above example, the node with the value 5 is the left child of the root node.
     
  • Right Child: Similarly, the node pointed by a node in its right is called its right child. In the above example, the node with the value 9 is the right child of the root node.
     
  • Parent Node: Every node is pointed by some node except for the root node; that node is known as its parent node. For example, the root node is the parent node for nodes with values 5 and 9.
     
  • Left Subtree: The tree whose root node is the left child of some node is called the left subtree of that node.
     
  • Right Subtree: The tree whose root node is the right child of some node is called the right subtree of that node.
     
  • Level of a Node: In easy words, the level of a node can be recognized as its distance from the root. The root level is said to be zero, and the level of the parent node is always one less than the child node.
     
  • Height or Depth of a Tree: The height or depth of a Binary Tree can be defined as the maximum number of nodes in a branch of the tree. We can also define the maximum number of nodes in a Binary Tree of depth ‘x’ as ‘2- 1’. The depth of the root node is said to be one.
     
  • Leaf Node: The node that does not have any child is known as Leaf Node.  

Difference Between Normal Tree and a Binary Tree

Normal Tree

Binary Tree

There is no restriction on every node in terms of children, i.e., a node can have an infinite number of children. Every node in a Binary Tree cannot have more than two children.
A normal tree cannot have a zero number of nodes. There can be an empty Binary Tree.
No distinction among children nodes. Children are distinguished in terms of left child and right child. 

Complete Binary Tree

A Binary Tree, in which all of its nodes are as left as possible and its depth can be defined as ‘logN + 1’ where ‘N’ is the number of nodes in it, then the tree will be recognized as a Complete Binary Tree.

Example:

 

Example of Complete Binary Tree

Full Binary Tree

A Binary Tree in which all the non-leaf nodes have two children and every leaf node is on the same level is called a Full Binary Tree.

For Example:

Example of a Full Binary Tree

Binary Expression Trees

A Binary Tree in which the root contains the operator and the left subtree stores the left expression and the right subtree stores the right expression. With respect to the precedence of evaluation, an expression having binary operators can be decomposed into 

<left operand or expression> (operator) <right operand or expression> 

 

Example: For the expression (p - q) / (r + s), construct a binary expression tree.

Must Read Binary Tree vs Binary Search Tree.

FAQs

1. What is a tree?
A tree is a data structure that stores data in the form of nodes to maintain a hierarchy.
 

2. What do you understand from the term Binary Tree?
A tree in which all the nodes do not have more than two children is called a Binary Tree.

3. What is a Complete Binary Tree?A Binary Tree in which all of its nodes in as left as possible and its depth can be defined as ‘logN + 1’ where ‘N’ is the number of nodes in it, then the tree will be recognized as a Complete Binary Tree.
 

4. What is a Full Binary Tree?
A Binary Tree in which all the non-leaf nodes have two children and every leaf node is on the same level is called a Full Binary Tree.

5. How can we define the depth or height of a Binary Tree?
The height or depth of a Binary Tree can be defined as the maximum number of nodes in a branch of the tree. We can also define the maximum number of nodes in a Binary Tree of depth ‘x’ as ‘2- 1’. The depth of the root node is said to be one.

Key Takeaways

In the above article, we have learned about Binary Trees and their properties. We also discussed several terminologies related to Trees and Binary Trees which would help you to enhance your knowledge related to Trees. 

 

Recommended problems -

 

In case you want to learn more about such concepts, head over to our library section for many such interesting blogs. Keep learning.

Happy Coding!

Live masterclass