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

Trees and Binary Trees

This document discusses trees and binary trees. It defines key terminology used for trees like root, internal nodes, leaves, ancestors, descendants, depth, height, and degree. It then describes properties of binary trees specifically, including full, complete, left-skewed and right-skewed binary trees. The document concludes by covering two common representations of binary trees - sequential using arrays and linked lists.

Uploaded by

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

Trees and Binary Trees

This document discusses trees and binary trees. It defines key terminology used for trees like root, internal nodes, leaves, ancestors, descendants, depth, height, and degree. It then describes properties of binary trees specifically, including full, complete, left-skewed and right-skewed binary trees. The document concludes by covering two common representations of binary trees - sequential using arrays and linked lists.

Uploaded by

seethamani p
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Trees and

Binary Trees
Objective of the sesson
• Tree
– Basic Terminologies
• Binary Tree
– Binary Tree – Representation
• Linear Data Structure and Non- Linear Data
Structure
Nature View of a Tree
leaves

branches
root
Computer Scientist’s View

root

leaves

branches
nodes
TREES
• Trees are one of the important non- Linear data
structure.
• A tree is a Multilevel data structure that represent a
hierarchical relationship between the Set of
individual elements called nodes.
• Each tree structure starts with a node Which is called
the root node of the Tree.
Tree Terminology
• Root: node without parent (A)
• Degree of a tree: the
• Siblings: nodes share the same
parent maximum number of its node.
• Internal node: node with at least • Subtree: tree consisting of a
one child (A, B, C, F) node and its descendants
• External node (leaf ): node
without children (E, I, J, K, G, H, D)
A
• Ancestors of a node: parent,
grandparent, grand-grandparent,
etc.
• Descendant of a node: child, B C D
grandchild, grand-grandchild, etc.
• Depth of a node: number of
ancestors E F G H
• Height of a tree: maximum depth
of any node (3)
• Degree of a node: the number of I J K
its children subtree
Binary Tree
• A tree in which every node can have a
maximum of two children is called as Binary
Tree.
Full Binary Tree
• A binary tree in which every node has either
two or zero number of children is called Full
Binary Tree
Complete Binary Tree
• A binary tree in which every internal node has exactly two
children and all leaf nodes are at same level is called
Complete Binary Tree. Complete binary tree is also called
as Perfect Binary Tree
• Number of nodes = 2d+1 – 1
• Number of leaf nodes = 2d
• Where, d – Depth of the tree
Left Skewed and Right Skewed
Trees
• Binary tree has only left sub trees - Left
Skewed Trees
• Binary tree has only right sub trees - Right
Skewed Trees
Binary Tree Representation
1. Sequential representation using arrays
2. List representation using Linked list
Sequential representation

• To represent a binary tree of depth ‘d' using array


representation, we need one dimensional array with a
maximum size of 2d+1 - 1.
Sequential representation
• Advantages:
– Direct access to all nodes (Random access)
• Disadvantages:
– Height of tree should be known
– Memory may be wasted
– Insertion and deletion of a node is difficult
List representation
struct node
{
int data;
struct node *left;
struct node *rifgt;
}
List representation
• Advantages:
– Height of tree need not be known
– No memory wastage
– Insertion and deletion of a node is done without
affecting other nodes
• Disadvantages:
– Direct access to node is difficult
– Additional memory required for storing address of
left and right node
Non-Linear Data Structure
• In a non linear data structure , the Elements are not
arranged in sequence.
• The data members are arranged in any Manner. The
data items are not processed one After another.
• Trees and graphs are examples of non linear data
structure.
Linear Data Structure
Vs
Non-Linear Data Structure
• In linear data structures, data elements are
organized sequentially and therefore they are
easy to implement in the computer’s memory.
• In nonlinear data structures, a data element
can be attached to several other data
elements to represent specific relationships
that exist among them.

You might also like