0% found this document useful (0 votes)
51 views

5.1 Binary Tree and Its Types

Binary tree is a tree data structure where each node has at most two children, called left and right children. There are four main types of binary trees: full binary tree where each node has either 0 or 2 children; complete binary tree where all levels are fully filled except the last; perfect binary tree where all internal nodes have 2 children and leaf nodes are on the same level; and degenerate binary tree where all nodes have only one child. Basic operations on binary trees include insertion, removal, searching, and traversing nodes.

Uploaded by

Ch Ahtasham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

5.1 Binary Tree and Its Types

Binary tree is a tree data structure where each node has at most two children, called left and right children. There are four main types of binary trees: full binary tree where each node has either 0 or 2 children; complete binary tree where all levels are fully filled except the last; perfect binary tree where all internal nodes have 2 children and leaf nodes are on the same level; and degenerate binary tree where all nodes have only one child. Basic operations on binary trees include insertion, removal, searching, and traversing nodes.

Uploaded by

Ch Ahtasham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q: What is binary tree DS and its types?

Binary Tree
Binary Tree is defined as a tree data structure where each node has at most 2 children. Since each element in a
binary tree can have only 2 children, we typically name them the left and right child.

Binary Tree Representation

A Binary tree is represented by a pointer to the topmost node (commonly known as the “root”) of the tree. If the
tree is empty, then the value of the root is NULL. Each node of a Binary Tree contains the following parts:

A) Data
B) Pointer to left child
C) Pointer to right child

The above tree is a binary tree because each node contains the utmost two children. The logical representation
of the above tree is given below:

In the above tree, node 1 contains two pointers, i.e., left and a right pointer pointing to the left and right node
respectively. The node 2 contains both the nodes (left and right node); therefore, it has two pointers (left and
right). The nodes 3, 5 and 6 are the leaf nodes, so all these nodes contain NULL pointer on both left and right
parts.

Basic Operation On Binary Tree:

 Inserting an element.
 Removing an element.
 Searching for an element.
 Traversing the tree.

Types of Binary Tree

There are four types of Binary tree:

o Full/ proper/ strict Binary tree


o Complete Binary tree
o Perfect Binary tree
o Degenerated

1. Full/ proper/ strict Binary tree

The full binary tree is also known as a strict binary tree. The tree can only be considered as the full binary tree if
each node must contain either 0 or 2 children. The full binary tree can also be defined as the tree in which each
node must contain 2 children except the leaf nodes.

Let's look at the simple example of the Full Binary tree.

In the above tree, we can observe that each node is either containing zero or two children; therefore, it is a Full
Binary tree.
2. Complete Binary Tree

The complete binary tree is a tree in which all the nodes are completely filled except the last level. In the last
level, all the nodes must be as left as possible. In a complete binary tree, the nodes should be added from the
left.

Let's create a complete binary tree.

3. Perfect Binary Tree

A tree is a perfect binary tree if all the internal nodes have 2 children, and all the leaf nodes are at the same
level.

4. Degenerate Binary Tree

The degenerate binary tree is a tree in which all the internal nodes have only one children.

Let's understand the Degenerate binary tree through examples.


The above tree is a degenerate binary tree because all the nodes have only one child. It is also known as a right-
skewed tree as all the nodes have a right child only.

The above tree is also a degenerate binary tree because all the nodes have only one child. It is also known as a
left-skewed tree as all the nodes have a left child only.

You might also like