SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Binary Tree
Definition - Operations -
Representations
Binary Tree and Complete Binary Tree
 Binary Tree(BT) is a tree in which each node contains at most two
child nodes(left child and right child).
 A complete binary tree is a binary tree in which every node
contains exactly two child nodes except the leaf nodes. Figure 1
shows a tree which is not a binary tree since node ‘3’ contains three
child nodes. Figure 2 shows an example binary tree and Figure 3
shows a complete binary tree
3
3 3
3 33
3
3 3
3 3
3
3 3
3 333
Figure 1 Figure 2 Figure 3
Types of Binary Tree
Ordered Binary Tree: In an ordered binary tree, the left
child node will always be less than its parent and right child
node will greater than its parent. It is also known as Binary
Search Tree.
Unordered Binary Tree: Unordered Binary tree does not
follow any such ordering.
An example of ordered binary tree is given below.
6
3 9
8 1051
In the rest of the slides we only
focus on ordered binary tree since it
has many applications including
finding duplicates, data sorting and
searching.
Operations on Binary tree
Traversals
•Traversal refers to visiting all the nodes of a binary
tree exactly once in a systematic way.
Insertion
•Refers to inserting a new element into the tree
Deletion
•Refers to removing an element from the tree
Searching
•Search operation checks whether the given data is
present in the tree or not.
Applications of Binary tree
• Expression Evaluation (Expression tree)
• Data Searching
• Data sorting
Representation of Binary Trees
Array Representation
Linked Representation
Threaded Representation
Array Representation
• A binary tree may be represented using an array.
• The key concept is that, if a parent is stored in location
k, then its left and right child are located in locations 2k
and 2k+1 respectively.
• An Example tree and its array representation is given
below.
6
3 9
8 1051
Location 1 2 3 4 5 6 7
Element 6 3 9 1 5 8 10
Traversal Operations
Pre-order Traversal
1. Process the root node
2. Perform preorder traversal of left subtree
3. perform preorder traversal of right subtree
In-order Traversal
1.Perform Inorder traversal of left subtree
2.Process the root node
3.Perform Inorder traversal of right subtree
Post-order Traversal
1.Perform Postorder traversal of left subtree
2.Perform Postorder traversal of right subtree
3.Process the root node
Traversal Operation - Examples

Inorder Traversal : 1 3 5 6 8 9 10
Preorder Traversal : 6 3 1 5 9 8 10
6
3 9
8 1051
NODE DECLARATION
typedef struct treeNode
{
int data;
struct treeNode *left;
struct treeNode *right;
}treeNode;
INSERTION ROUTINE
treeNode * Insert(treeNode *node,int data)
{
if(node==NULL)
{
treeNode *temp;
temp = (treeNode *)malloc(sizeof(treeNode));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = Insert(node->right,data);
}
else if(data < (node->data))
{
node->left = Insert(node->left,data);
}
/* Else there is nothing to do as the data is already in the tree. */
return node;
}
DELETION ROUTINE
treeNode * Delete(treeNode *node, int data)
{
treeNode *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = Delete(node->left, data);
}
else if(data > node->data)
{
node->right = Delete(node->right, data);
}
else
{
/* Now We can delete this node and replace with either minimum element
in the right sub tree or maximum element in the left subtree */
CONTD..
  if(node->right && node->left)
                {
                        /* Here we will replace with minimum element in the right sub tree */
                        temp = FindMin(node->right);
                        node -> data = temp->data; 
                        /* As we replaced it with some other node, we have to delete that node */
                        node -> right = Delete(node->right,temp->data);
                }
                else
                {
                        /* If there is only one or zero children then we can directly 
                           remove it from the tree and connect its parent to its child */
                        temp = node;
                        if(node->left == NULL)
                                node = node->right;
                        else if(node->right == NULL)
                                node = node->left;
                        free(temp); /* temp is longer required */ 
                }
        }
        return node;
}
FINDMIN ROUTINE
treeNode* FindMin(treeNode *node)
{
        if(node==NULL)
        {
                /* There is no element in the tree */
                return NULL;
        }
        if(node->left) /* Go to the left sub tree to find the min 
element */
                return FindMin(node->left);
        else 
                return node;
}
                                                                                               
How many squares can you create in this figure by connecting any 4 dots (the corners of a 
square must lie upon a grid dot?
TRIANGLES: 
How many triangles are located in the image below?
There are 11 squares total; 5 small, 4 medium, and 2 large.
27 triangles.  There are 16 one-cell triangles, 7 four-cell triangles, 3 nine-cell 
triangles, and 1 sixteen-cell triangle.
GUIDED READING
1.1 binary tree
ASSESSMENT
1. A binary tree whose every node has either
zero or two children is called
A. Complete binary tree
B. Binary search tree
C. Extended binary tree
D. None of above
Contd..
2. The depth of a complete binary tree is
given by
A. Dn = n log2n
B. Dn = n log2n+1
C. Dn = log2n
D. Dn = log2n+1
Contd..
3.The post order traversal of a binary tree is
DEBFCA. Find out the pre order traversal
A. ABFCDE
B. ADBFEC
C. ABDECF
D. ABDCEF
Contd..
4.In a binary tree, certain null entries are
replaced by special pointers which point to
nodes higher in the tree for efficiency. These
special pointers are called
A. Leaf
B. branch
C. path
D. thread
Contd..
5. The in-order traversal of tree will yield a
sorted listing of elements of tree in
A. Binary trees
B. Binary search trees
C. Heaps
D. None of above

More Related Content

PPTX
Tree - Data Structure
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Binary Search Tree in Data Structure
PDF
Data structure ppt
PPTX
Binary Search Tree
PPTX
Tree in data structure
PDF
Binary tree
PPTX
trees in data structure
Tree - Data Structure
BINARY TREE REPRESENTATION.ppt
Binary Search Tree in Data Structure
Data structure ppt
Binary Search Tree
Tree in data structure
Binary tree
trees in data structure

What's hot (20)

PPTX
Stacks and Queue - Data Structures
PPTX
Data structure - Graph
PPTX
Linked list
PPTX
Graph in data structure
PPTX
Binary Tree in Data Structure
PDF
UNIT III NON LINEAR DATA STRUCTURES – TREES
PPTX
Binary Tree Traversal
PPTX
stack & queue
PPSX
Data Structure (Queue)
PDF
Applications of stack
PPTX
linked list in data structure
PDF
Binary search tree operations
PPTX
Linked list
PPT
Abstract data types
PPTX
Queue ppt
PPTX
STACKS IN DATASTRUCTURE
PPT
Binary tree
PPT
PPTX
Queue in Data Structure
PPTX
Doubly Linked List
Stacks and Queue - Data Structures
Data structure - Graph
Linked list
Graph in data structure
Binary Tree in Data Structure
UNIT III NON LINEAR DATA STRUCTURES – TREES
Binary Tree Traversal
stack & queue
Data Structure (Queue)
Applications of stack
linked list in data structure
Binary search tree operations
Linked list
Abstract data types
Queue ppt
STACKS IN DATASTRUCTURE
Binary tree
Queue in Data Structure
Doubly Linked List
Ad

Viewers also liked (20)

PPT
Binary tree
PPTX
PPTX
Binary tree and Binary search tree
PDF
Binary tree
PDF
Tree and binary tree
PDF
Threaded binarytree&heapsort
PPTX
THREADED BINARY TREE AND BINARY SEARCH TREE
PPTX
Tree in Discrete structure
PPT
Binary trees
PPTX
Threaded Binary Tree
PPTX
Altar de Muertos
PPT
binary tree
PPT
Top Forex Brokers
PPT
2.4 mst kruskal’s
PPT
5.2 divede and conquer 03
PPT
5.3 dyn algo-i
PPT
4.1 webminig
PPT
4.2 bst 03
DOCX
Salario minimo basico
Binary tree
Binary tree and Binary search tree
Binary tree
Tree and binary tree
Threaded binarytree&heapsort
THREADED BINARY TREE AND BINARY SEARCH TREE
Tree in Discrete structure
Binary trees
Threaded Binary Tree
Altar de Muertos
binary tree
Top Forex Brokers
2.4 mst kruskal’s
5.2 divede and conquer 03
5.3 dyn algo-i
4.1 webminig
4.2 bst 03
Salario minimo basico
Ad

Similar to 1.1 binary tree (20)

PPTX
Binary tree operations in data structures
PPTX
presentation 1 binary search tree in data structures.pptx
PDF
Treeeeeeeeeeeeeeeeereeeeeeeeeeeeeeee.pdf
PPTX
Binary tree
PPTX
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
PPTX
Binary Search Tree in Data Structure
PPTX
4. Apply data structures such as arrays, linked lists, and trees as an abstra...
PPTX
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
PDF
Unit iv data structure-converted
PPTX
Data Strcutres-Non Linear DS-Advanced Trees
DOCX
Biary search Tree.docx
PDF
Trees second part in data structures with examples
PPT
Introduction to data structure by anil dutt
PDF
PPTX
Trees in data structure
PPTX
DAA PPT.pptx
PPTX
Binary Search Tree
PPTX
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
Binary tree
Binary tree operations in data structures
presentation 1 binary search tree in data structures.pptx
Treeeeeeeeeeeeeeeeereeeeeeeeeeeeeeee.pdf
Binary tree
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
Binary Search Tree in Data Structure
4. Apply data structures such as arrays, linked lists, and trees as an abstra...
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
Unit iv data structure-converted
Data Strcutres-Non Linear DS-Advanced Trees
Biary search Tree.docx
Trees second part in data structures with examples
Introduction to data structure by anil dutt
Trees in data structure
DAA PPT.pptx
Binary Search Tree
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
UNIT III Non Linear Data Structures - Trees.pptx
Binary tree

More from Krish_ver2 (20)

PPT
5.5 back tracking
PPT
5.5 back track
PPT
5.5 back tracking 02
PPT
5.4 randomized datastructures
PPT
5.4 randomized datastructures
PPT
5.4 randamized algorithm
PPT
5.3 dynamic programming 03
PPT
5.3 dynamic programming
PPT
5.2 divede and conquer 03
PPT
5.2 divide and conquer
PPT
5.1 greedyyy 02
PPT
5.1 greedy
PPT
5.1 greedy 03
PPT
4.4 hashing02
PPT
4.4 hashing
PPT
4.4 hashing ext
PPT
4.4 external hashing
PPT
4.2 bst
PPT
4.2 bst 02
PPT
4.1 sequentioal search
5.5 back tracking
5.5 back track
5.5 back tracking 02
5.4 randomized datastructures
5.4 randomized datastructures
5.4 randamized algorithm
5.3 dynamic programming 03
5.3 dynamic programming
5.2 divede and conquer 03
5.2 divide and conquer
5.1 greedyyy 02
5.1 greedy
5.1 greedy 03
4.4 hashing02
4.4 hashing
4.4 hashing ext
4.4 external hashing
4.2 bst
4.2 bst 02
4.1 sequentioal search

Recently uploaded (20)

PDF
Open folder Downloads.pdf yes yes ges yes
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
master seminar digital applications in india
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Open folder Downloads.pdf yes yes ges yes
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharma ospi slides which help in ospi learning
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Microbial disease of the cardiovascular and lymphatic systems
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
human mycosis Human fungal infections are called human mycosis..pptx
master seminar digital applications in india
O7-L3 Supply Chain Operations - ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Final Stretch: How to Release a Game and Not Die in the Process.
Basic Mud Logging Guide for educational purpose
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table

1.1 binary tree