Unit-V Trees Mfcs
Unit-V Trees Mfcs
Unit-V Trees Mfcs
Valid Invalid
27
2.A full binary tree
• A full binary tree (sometimes proper binary tree or 2-
tree) is a tree in which every node other than the leaves
has two children.
• The number of nodes, n, in a full binary tree is atleast n = 2h –
1, and atmost n = 2h+1 – 1, where h is the height of the tree.
• The number of leaf nodes l, in a full binary tree is number, L of
internal nodes + 1, i.e, l = L+1.
Perfect binary tree:
• Perfect binary tree: It is a binary tree in which all interior nodes
have two children and all leaves have the same depth or same
level.
• A perfect binary tree with l leaves has n = 2l-1 nodes.
• In perfect full binary tree, l = 2h and n = 2h+1 - 1 where, n is
number of nodes, h is height of tree and l is number of leaf nodes
Perfect binary tree
Valid Invalid
3. Complete Binary Tree
•In complete binary tree all the nodes must have exactly two
children and at every level of complete binary tree there must be
2level number of nodes. It is also called as Perfect Binary Tree
• For example at level 2 there must be 22 = 4 nodes and at level 3
there must be 23 = 8 nodes.
•A complete binary tree is a binary tree in which every level, except
possibly the last, is completely filled, and all nodes are as far left as
possible
3. Complete Binary Tree
Valid Invalid
4. Extended Binary Tree
A binary tree can be converted into Full Binary tree by
adding dummy nodes to existing nodes wherever required.
The full binary tree obtained by adding dummy nodes to a
binary tree is called as Extended Binary Tree.
5. Balanced Binary Tree
Balanced Binary Tree is a Binary tree in which height of the left
and the right sub-trees of every node may differ by at most 1.
Valid BT Invalid BT
34
5. Degenerate(or Pathological) Binary Tree
Valid Invalid
35
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
. Array Representation of Binary
• we use one- Tree
dimensional array (1-D
Array) to represent a
binary tree.
To represent a binary
tree of depth 'n' using
array representation,
we need one
dimensional array with
a maximum size
of 2n+1 + 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...
•
2. Linked List Representation of Binary Tree
Trees
• A Tree is a special type of connected graph in which there are no
circuits.
• Every tree is a bipartite graph.
• So, chromatic number of a tree with any number of vertices = 2.
Tree
A tree is a connected undirected graph that does not contain
a simple circuit.
Forest
• If each component of a graph G is a tree, G is
called a forest.
Graph Traversal - DFS
Graph
Some of the possible spanning trees that can be created from the above graph are:
Minimum Spanning Tree
• A minimum spanning tree is a spanning tree in which the sum
of the weight of the edges is as minimum as possible.
• The minimum spanning tree from the above spanning trees is:
Applications
Spanning Tree Applications
• Computer Network Routing Protocol
• Cluster Analysis
• Civil Network Planning
Minimum Spanning tree Applications
• To find paths in the map
• To design networks like telecommunication
networks, water supply networks, and
electrical grids.
• The minimum spanning tree from a graph is
found using the following algorithms:
• Prim's Algorithm
• Kruskal's Algorithm
•