0% found this document useful (0 votes)
2 views21 pages

DSA-II UNIT-I Binary Tree Traversal

The document provides an overview of binary tree traversals, detailing the two main approaches: Breadth First and Depth First, with specific algorithms for Preorder, Inorder, and Postorder traversals. It includes examples and exercises for each traversal method, along with a problem to construct an expression tree. The document emphasizes the importance of processing each node in a predetermined sequence.

Uploaded by

Ms. Pavithra D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views21 pages

DSA-II UNIT-I Binary Tree Traversal

The document provides an overview of binary tree traversals, detailing the two main approaches: Breadth First and Depth First, with specific algorithms for Preorder, Inorder, and Postorder traversals. It includes examples and exercises for each traversal method, along with a problem to construct an expression tree. The document emphasizes the importance of processing each node in a predetermined sequence.

Uploaded by

Ms. Pavithra D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

DATA STRUCTURES

UNIT-I-TREES

BINARY TREE TRAVERSAL


BINARY TREE TRAVERSALS
🞆 A binary tree traversal requires that
each node of the tree be processed
once and only once in a
predetermined sequence.
🞆 The two general approaches to the
traversal sequence are:
• Breadth First Traversal
• Depth First Traversal
⮚Preorder Traversal
⮚Inorder Traversal
⮚Postorder Traversal
PREORDER TRAVERSAL
🞆 Processing order:
Root → Left → Right
Algorithm
1. Visit the root
2. Traverse the left sub tree i.e. call
Preorder (left sub tree)
3. Traverse the right sub tree i.e. call
Preorder (right sub tree)
EXAMPLE
INORDER TRAVERSAL
🞆 Processing order:
Left → Root → Right
Algorithm
1. Traverse the left sub tree i.e. call Inorder
(left sub tree)
2. Visit the root
3. Traverse the right sub tree i.e. call Inorder
(right sub tree)
EXAMPLE
POSTORDER TRAVERSAL
🞆 Processing order:
Left → Right → Root
Algorithm
1. Traverse the left sub tree i.e. call Postorder
(left sub tree)
2. Traverse the right sub tree i.e. call
Postorder (right sub tree)
3. Visit the root
EXAMPLE
VISUALIZATION
VISUALIZATION
VISUALIZATION
Q7
Find
🞆 Level order:
🞆 Inorder:
🞆 Preorder:
🞆 Postorder:
ANS
🞆 Level order: 8 5 4 9 7 11 1 12 3 2
🞆 Inorder: 9 5 1 7 2 128 4 3 11
🞆 Preorder: 8 5 97 1 12 2 4 11 3
🞆 Postorder:9 1 2 12 7 5 3 11 4 8
EXERCISE PROBLEM-TREE TRAVERSAL

🞆 Inorder: 7, 9,4,2,5,1,3,6,8
🞆 Preorder: 1,2,4,7,9,5,3,6,8
🞆 Postorder: 9,7,4,5,2,8,6,3,1
EXERCISE PROBLEM-TREE TRAVERSAL

🞆 Inorder: 9,2,7,1,7,4,6,1,8,3,5
🞆 Preorder: 6,7,2,9,7,1,4,8,1,3,5
🞆 Postorder: 9,2,1,4,7,7,1,5,3,8,6
EXERCISE PROBLEM-TREE TRAVERSAL
🞆 Inorder:
🞆 Preorder:
🞆 Postorder:
EXERCISE PROBLEM
🞆 Construct an expression tree for the
expression A+(B-C)*D*(E+F)
THANK YOU

You might also like