Sandesh Daundkar
Sandesh Daundkar | Blogs

Sandesh Daundkar | Blogs

Binary Trees

Photo by Kenny Eliason on Unsplash

Binary Trees

Binary Tree/ N-Ary Tree

Sandesh Daundkar's photo
Sandesh Daundkar
ยทAug 6, 2022ยท

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Hello Everyone ๐Ÿ™‹๐Ÿปโ€โ™‚๏ธ,

In this article, we will try to understand what are binary trees, as we go along we will be exploring different tree data structures so we must have a basic understanding of the binary tree.

A binary tree is a tree comprising nodes, with each node having at most two other nodes referred to as the left child and the right child of the node.

Each node contains three components data element, pointer to the left child and pointer to the right child, they are recursively defined. If there is no child the pointer points to null.

A data element can be any type of data, while the left and the right pointer point to binary trees on the left and the right side of the node respectively.

The image below represents a binary tree and the node structure if you extract a node element. image.png

Binary Tree in Python

class BinaryTree:
    def __init__(self, data): = data
        self.left = None
        self.right = None

root_node = Node(1)
Some important definitions
  • The topmost node is called the root node.
  • The nodes that are connected downwards and are next to each other are called children.
  • The node without any children is called a leaf node.
  • Node with at least one child is called an internal node.
  • Node without any child is called an external node.
  • Nodes with the same parent are called siblings.
Types of Binary Trees
  • Full Binary Tree
  • Complete Binary Tree
  • Perfect Binary Tree
  • Degenerate Binary Tree
  • Balanced Binary Tree

I hope this article gave you a basic understanding of the binary tree. We will be exploring each type of BT in the later articles.

Thanks for reading ๐Ÿ™‡๐Ÿปโ€โ™‚๏ธ


Share this