#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Trees

Binary Tree in Data Structure — Types and Implementation

A Binary Tree is a hierarchical data structure in which each node has at most two children, commonly referred to as the left child and the right child.

Types of Binary Trees

TypeDescription
Full Binary TreeEvery node has either 0 or 2 children.
Complete Binary TreeAll levels are completely filled except possibly the last, which is filled left to right.
Perfect Binary TreeAll internal nodes have two children and all leaves are at the same level.
Balanced Binary TreeThe height of the left and right subtrees of any node differ by at most one.
Degenerate (Skewed) TreeEach parent node has only one child, resembling a linked list.

Linked Node Implementation

class Node:
    def __init__(self, value):
        self.val = value
        self.left = None
        self.right = None

class BinaryTree:
    def __init__(self):
        self.root = None

    def insert_level_order(self, values):
        # builds a complete binary tree from a list, left to right
        if not values:
            return
        self.root = Node(values[0])
        queue = [self.root]
        i = 1
        while queue and i < len(values):
            node = queue.pop(0)
            if i < len(values):
                node.left = Node(values[i]); queue.append(node.left); i += 1
            if i < len(values):
                node.right = Node(values[i]); queue.append(node.right); i += 1

Complexity

OperationTime
Search/Insert/Delete (unbalanced)O(n)
Search/Insert/Delete (balanced)O(log n)

Applications

  • Expression trees for evaluating mathematical expressions.
  • Binary Search Trees for fast lookup.
  • Huffman coding trees for data compression.

Ready to master Data Structures & Algorithms?

Learn DSA hands-on with mentor-led sessions, real interview practice, and placement support.

Explore Course