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

Binary Tree

A binary tree is a data structure where each node can have up to two children, categorized into unlabeled and labeled trees. With 3 unlabeled nodes, 5 unique structures are possible, while 30 labeled trees can be formed from the same configuration. Binary trees can be classified into several types, including rooted, full, complete, almost complete, and skewed, and can be represented using array or linked list methods.

Uploaded by

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

Binary Tree

A binary tree is a data structure where each node can have up to two children, categorized into unlabeled and labeled trees. With 3 unlabeled nodes, 5 unique structures are possible, while 30 labeled trees can be formed from the same configuration. Binary trees can be classified into several types, including rooted, full, complete, almost complete, and skewed, and can be represented using array or linked list methods.

Uploaded by

Ritika Lohiya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Binary Tree-

Binary tree is a special tree data structure in which each node can have at most 2 children.
Thus, in a binary tree,
Each node has either 0 child or 1 child or 2 children.

Example-

Unlabeled Binary Tree-

A binary tree is unlabeled if its nodes are not assigned any label.
Example-

Consider we want to draw all the binary trees possible with 3 unlabeled nodes.
Using the above formula, we have-

Number of binary trees possible with 3 unlabeled nodes


= 2 x 3C3 / (3 + 1)
= 6C3 / 4
=5

Thus,
• With 3 unlabeled nodes, 5 unlabeled binary trees are possible.
• These unlabeled binary trees are as follows-

Labeled Binary Tree-

A binary tree is labeled if all its nodes are assigned a label.


Example-

Consider we want to draw all the binary trees possible with 3 labeled nodes.
Using the above formula, we have-

Number of binary trees possible with 3 labeled nodes


= { 2 x 3C3 / (3 + 1) } x 3!
= { 6C3 / 4 } x 6
=5x6
= 30

Thus,
• With 3 labeled nodes, 30 labeled binary trees are possible.
• Each unlabeled structure gives rise to 3! = 6 different labeled structures.
Similarly,
• Every other unlabeled structure gives rise to 6 different labeled structures.
• Thus, in total 30 different labeled binary trees are possible.

Types of Binary Trees-

Binary trees can be of the following types-


1. Rooted Binary Tree
2. Full / Strictly Binary Tree
3. Complete / Perfect Binary Tree
4. Almost Complete Binary Tree
5. Skewed Binary Tree

1. Rooted Binary Tree-

A rooted binary tree is a binary tree that satisfies the following 2 properties-
• It has a root node.
• Each node has at most 2 children.

Example-
2. Full / Strictly Binary Tree-

• A binary tree in which every node has either 0 or 2 children is called as a Full
binary tree.
• Full binary tree is also called as Strictly binary tree.

Example-
Here,
• First binary tree is not a full binary tree.
• This is because node C has only 1 child.

3. Complete / Perfect Binary Tree-

A complete binary tree is a binary tree that satisfies the following 2 properties-
• Every internal node has exactly 2 children.
• All the leaf nodes are at the same level.

Complete binary tree is also called as Perfect binary tree.

Example-

Here,
• First binary tree is not a complete binary tree.
• This is because all the leaf nodes are not at the same level.

4. Almost Complete Binary Tree-

An almost complete binary tree is a binary tree that satisfies the following 2 properties-
• All the levels are completely filled except possibly the last level.
• The last level must be strictly filled from left to right.
Example-

Here,
• First binary tree is not an almost complete binary tree.
• This is because the last level is not filled from left to right.

5. Skewed Binary Tree-

A skewed binary tree is a binary tree that satisfies the following 2 properties-
• All the nodes except one node has one and only one child.
• The remaining node has no child.
OR
A skewed binary tree is a binary tree of n nodes such that its depth is (n-1).

Example-
Binary Tree Representations

A binary tree data structure is represented using two methods. Those methods are as

follows...

1. Array Representation

2. Linked List Representation

Consider the following binary tree...


1. Array Representation of Binary Tree

In array representation of a binary tree, we use one-dimensional array (1-D Array) to

represent a binary tree.

Consider the above example of a binary tree and it is represented as follows...

To represent a binary tree of depth 'n' using array representation, we need one dimensional

array with a maximum size of 2n + 1.

2. Linked List Representation of Binary Tree

We use a double linked list to represent a binary tree. In a double linked list, every node

consists of three fields. First field for storing left child address, second for storing actual data

and third for storing right child address.

In this linked list representation, a node has the following structure...

The above example of the binary tree represented using Linked list representation is shown

as follows...

You might also like