Data Structure - 11 Tree Traversal

AndiNurkholis1 2 views 13 slides Oct 17, 2025
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

The Tree Traversal slide the Data Structures course include:
1. Concept of tree traversal
2. Key terms of tree traversal
3. Category of tree traversal
4. Depth-first traversal
5. Breadth-first traversal
6. Importance of tree traversal
7. Application of tree traversal


Slide Content

Department of Informatics
Faculty of Industrial Engineering
Universitas Pembangunan Nasional “Veteran” Yogyakarta
Data
Structure
Andi Nurkholis, S.Kom., M.Kom.
Tree
Traversal
November 17, 2025

Concept of Tree Traversal
Tree traversal is the systematic process
of visiting each node in a tree structure
to read, process, or manipulate the data
stored within it.
This process plays a crucial role in
searching, sorting, expression
evaluation, and hierarchical structure
processing, which can be performed
either recursively or iteratively
depending on the type of tree and the
processing objective.

Key Terms of Tree Traversal
Basic terms related to trees:
üNode: The fundamental element in a tree that stores data.
üRoot: The topmost node in a tree.
üLeaf Node: A node that has no children.
üSubtree: A tree structure contained within another tree.
üHeight & Depth: Height is the length of the longest path from a node to a
leaf, while depth is the length of the path from the root to that node.

Key Terms of Tree Traversal
There are several common traversal methods, each with different purposes and
approaches. As an illustration, consider the following tree:
A
/ \
B C
/ \ \
D E F
üPreorder: A B D E C F
üInorder: D B E A C F
üPostorder: D E B F C A
üLevel-order: A B C D E F

Category ofTree Traversal
1.Depth-First Traversal (DFT)
2.Breadth-First Traversal (BFT)

Depth-First Traversal
Traversal that focuses on exploring each
branch of the tree as deeply as possible before
moving to another branch. DFT is typically
implemented recursively, though it can also be
done using a stack. The types of DFT include:
üPreorder Traversal (Root – Left – Right):
The root node is visited first, followed by the
left subtree, and finally the right subtree. This
method is suitable for creating a copy of the
tree or evaluating expressions in prefix form.
Example order: A, B, D, E, C, F.

Depth-First Traversal
üInorder Traversal (Left – Root – Right): The left subtree is visited first,
followed by the root node, and finally the right subtree. In a Binary Search
Tree (BST), this traversal produces data in ascending order, making it useful
for sorting and data searching.
üPostorder Traversal (Left – Right – Root): The left subtree is visited first,
then the right subtree, and finally the root node. This method is used in
operations that require processing child nodes before the parent, such as tree
deletion or postfix expression evaluation.

Breadth-First Traversal
This traversal visits nodes level by level,
starting from the root node (level 0), then
all nodes at the next level from left to right.
It is typically implemented using a queue.
BFT is widely used in shortest path
algorithms, tree height calculation, and
tree structure visualization.

Importance of Tree Traversal
The Importance of Tree Traversal in Data Structures:
1.Systematic Data Processing: Provides a structured way to access and
manipulate each node.
2.Foundation for Advanced Algorithms: Traversal serves as the basis for
algorithms in binary search trees, AVL trees, mathematical expression
parsing, and pathfinding.
3.Performance Optimization: Choosing the right traversal method can
enhance the efficiency of searching, storing, and manipulating data across
various applications.

Application of Tree Traversal
1.Data Structures and File Systems: Tree traversal is used to explore the
hierarchical structure of folders and files; pre-order traversal displays the
creation order, while post-order traversal is useful for recursive deletion.
2.Database Indexing and Searching: Tree structures such as B-Trees and B+
Trees utilize traversal for data searching and manipulation; in-order traversal
ensures ordered data retrieval to accelerate queries.

Application of Tree Traversal
3.Compilation and Expression Parsing: The Abstract Syntax Tree (AST)
represents the syntactic structure of a program; post-order traversal is used
to evaluate arithmetic expressions, while pre-order traversal is used to
generate machine code.
4.Artificial Intelligence and Game Development: Search trees and decision
trees use traversals such as DFS and BFS to explore game moves, plan paths,
and make decisions in AI algorithms.

Application of Tree Traversal
5.Data Compression and Processing: The Huffman Coding algorithm uses tree
traversal to generate optimal binary codes; pre-order traversal constructs the
code table, while post-order traversal is used for decompression.
6.Computer Networks and Routing: Traversal on a spanning tree ensures data
distribution without loops, while Kruskal’s and Prim’s algorithms utilize tree
traversal to form optimal network paths.
7.Data Science and Machine Learning: Traversal is used in Decision Trees
and Random Forests to trace nodes from root to leaf, enabling systematic
classification and prediction based on conditions at each node.

Department of Informatics
Faculty of Industrial Engineering
Universitas Pembangunan Nasional “Veteran” Yogyakarta
Andi Nurkholis, S.Kom., M.Kom.
November 17, 2025
Done
Thank
You