You are on page 1of 10

CSE 1107: Discrete Mathematics

M.M.A. Hashem, PhD


Professor,
Dept. of Computer Science and Engineering
Khulna University of Engineering & Technology (KUET)
Khulna 9203, Bangladesh
Email; hashem@cse.kuet.ac.bd
Cell Phone: +880 1714 003949
Objectives for Today

• Understand Trees/Terminology
• Use Basic Traversals on Trees

April 14, 2024 CSE 1107: Discrete Mathematics 2


Trees
• Nonlinear Data Structure

April 14, 2024 CSE 1107: Discrete Mathematics 3


Tree Terminology

• root, leaf • external, internal node


• parent, child, sibling • ancestor, descendant
• subtree • depth, height
April 14, 2024 CSE 1107: Discrete Mathematics 4
Binary Trees
• Each node has 0, 1, or 2 children

April 14, 2024 CSE 1107: Discrete Mathematics 5


Binary Tree Application:
Huffman Tree (Data
Compression)

April 14, 2024 CSE 1107: Discrete Mathematics 6


Tree Traversal
• Process of Visiting Each Node
• 4 Different Standard Traversals:
– Preorder
– Inorder
– Postorder
– Level-order (also called breadth-first)

April 14, 2024 CSE 1107: Discrete Mathematics 7


April 14, 2024 CSE 1107: Discrete Mathematics 8
Traversal Exercise
Find the:
• Preorder
• Inorder
• Postorder
• Level-order

April 14, 2024 CSE 1107: Discrete Mathematics 9


Answers of the Exercise

• Preorder traversal sequence:


F, B, A, D, C, E, G, I, H (root, left, right)
• Inorder traversal sequence:
A, B, C, D, E, F, G, H, I (left, root, right)
• Postorder traversal sequence:
A, C, E, D, B, H, I, G, F (left, right, root)
• Level-order traversal sequence:
F, B, G, A, D, I, C, E, H
April 14, 2024 CSE 1107: Discrete Mathematics 10

You might also like