Tree
Adam M.B.
TREE
TRAVERSAL

Types of Tree Traversal
• Preorder : Node – Left - Right
• Inorder : Left – Node - Right
• Postorder : Left – Right - Node
Ilustration (1)
H
A
L
K
B
C J
Preorder (NLR) : HA KCB JL
Inorder (LNR) : HA KCB J L
Postorder (LRN) : HA KCB JL
Ilustration (2)
Preorder (NLR) : ABDE C GH
Inorder (LNR) :
Postorder (LRN) :
A
B
H
CD
E F
GI
I F
ABD E CGHI F
ABDE CGHI F
Case
Prefix : / + A- B DH
Infix :
Postfix:
/
+
^
-
A
B
F
*
D
* ^
E = A + BDH – F
G - K
A + B * D^ H- F )( / G( - )E = K
H
-
KG
GK-F
/+A -B D H* ^ G K-F
/+A -BDH *^ GK -F
Subtree Kiri Subtree
Kanan
Root
Make binary tree from this general tree
and do the tree traversal process:
Exercise
A
B
H
C
D E F GI
R
P
Q
TREE TRAVERSAL
INTO BINARY TREE

Example 1
Preorder :
Inorder :
J
B
H
CD
E F
GI
BDEI F GJC H
DIEB F CJH G
Example 2
Inorder :
Postorder :
J
B
H
CD
E F
GI
IEDH F CBG J
DIEB F CJH G
Make binary tree from these result of tree
traversal:
• Inorder : BCDFGKMPSUWY
Preorder : MFDBCKGSPWUY
• Postorder : EGHCIMFBNPJLKDA
Inorder : EBGCHFMIANJPDLK
Exercise
m
TREE TRAVERSAL
USING STACK

Node have 2
Using Preorder
Rules :
• If scanned node has 2 children then
PUSH its right son (RS).
• If scanned node hasn’t child then POP
element of stack.
Node have 2
Using Preorder
Notes :
• Arrow down (↓) means PUSH.
• Arrow up (↑) means POP.
• LS : Left Son
• RS : Right Son
Node have 2
Using Preorder
A
B
H
CD
E F
GI
Preorder (NLR) :
Head B D E I C
F G H A
BDEICFGHA
LS RS LS
RS B RS B
LS RS RS
RS C
RS C
Node have 2
Using Inorder
Rules and Note :
• If scanned node has left child then PUSH
itself (Scanned Node Address).
• If scanned node hasn’t child then POP
element of stack.
• Add = Address.
Node have 2
Using Inorder
A
B
H
CD
E F
GI
Inorder (LNR) :
Head B D E I E
B C F G
DIEBFGHCA
LS RS LS
Add. B Add. E
RS LS
Add. C
Add. BAdd. E
Add. C
RS RS H
RSC A
Node have 2
Using Postorder
Rules :
• If scanned node has 2 children then PUSH
itself (Scanned Node Address) and its right
child.
• If scanned node has only 1 child then PUSH
itself (Scanned Node Address).
• If scanned node hasn’t child then POP element
of stack.
Node have 2
Using Postorder
A
B
H
CD
E F
GI
Postorder (LRN) :
Head B D E I E
D C F G
IEDHGFACB
LS RS LS
RS B
Add. E
LS
RS B
Add. D
G F A C
H
Add B
RS
Add C
Add D Add E
RS C
Add C Add F
RS
Add G Add G
Add F RS C
B
Add B
Traverse this tree using stack (3 ways):
Exercise 1
A
B
H
C
D E
FI
Make binary tree from this statement then
traverse binary tree using stack (3 ways):
Exercise 2
E = A + (B-D)H – F
GK
Make binary in linked list form from these result
of tree traversal and traverse the result using
stack in postorder way:
Preorder : RFCAEDLHPVTZXWY
Inorder : ACDEFHLPRTVWXYZ
Exercise 3
Make binary tree from this general tree and traverse
the result using preorder, inorder, and postorder:
Exercise 4
S
B
L
D
E F J K
MC
G H
I
N P
X
A PY
Contact Person:
Adam Mukharil Bachtiar
Informatics Engineering UNIKOM
Jalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: adfbipotter@gmail.com
Blog: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2012

More Related Content

PDF
Comprehensive wavelengths and energy levels of Fe II, Cr II and other iron-gr...
DOCX
контрольная работа №4
PPT
PDF
Fellow of HEA Certificate
PPT
внеклассное мероприятие путешествие с инфознайкой
PDF
OSHA Certificate for Rajesh Gomes
PDF
Media Scanner for Resolution Services - Client
PPTX
Ruby Conf Brasil 2015
Comprehensive wavelengths and energy levels of Fe II, Cr II and other iron-gr...
контрольная работа №4
Fellow of HEA Certificate
внеклассное мероприятие путешествие с инфознайкой
OSHA Certificate for Rajesh Gomes
Media Scanner for Resolution Services - Client
Ruby Conf Brasil 2015

Viewers also liked (14)

PDF
Looking for a radiant skin, look out for radiation
PPTX
Installation & configuration of IBM Cloud Orchestrator v2.5
PDF
Mutant Testing: um mundo para um X-Testing.
PPT
Guazzaroni M. Nuove Metodiche Radiologiche nelle Emergenze Stroke. ASMaD 2012
PPTX
данные и устройства для работы с ними
PPTX
графические объекты
PPTX
компьютерные презентации
PPTX
правила складання ребусів
PPTX
Verizon taking over yahoo
PPTX
интересные факты о информатике
PPTX
Yahoo analysis-
PPSX
Data Structure (Tree)
PDF
Data Management (Data Mining Klasifikasi)
PDF
Tree and binary tree
Looking for a radiant skin, look out for radiation
Installation & configuration of IBM Cloud Orchestrator v2.5
Mutant Testing: um mundo para um X-Testing.
Guazzaroni M. Nuove Metodiche Radiologiche nelle Emergenze Stroke. ASMaD 2012
данные и устройства для работы с ними
графические объекты
компьютерные презентации
правила складання ребусів
Verizon taking over yahoo
интересные факты о информатике
Yahoo analysis-
Data Structure (Tree)
Data Management (Data Mining Klasifikasi)
Tree and binary tree
Ad

More from Adam Mukharil Bachtiar (20)

PDF
Materi 8 - Data Mining Association Rule.pdf
PDF
Clean Code - Formatting Code
PDF
Clean Code - Clean Comments
PDF
PDF
Clean Code and Design Pattern - Meaningful Names
PDF
Model Driven Software Development
PDF
Scrum: How to Implement
PDF
Pengujian Perangkat Lunak
PDF
Data Mining Clustering
PPTX
Data Mining Klasifikasi (Updated 30 Desember 2020)
PDF
Analisis Algoritma - Strategi Algoritma Dynamic Programming
PDF
Analisis Algoritma - Strategi Algoritma Divide and Conquer
PDF
Analisis Algoritma - Strategi Algoritma Greedy
PDF
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
PDF
Analisis Algoritma - Strategi Algoritma Brute Force
PDF
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
PDF
Analisis Algoritma - Teorema Notasi Asimptotik
PDF
Analisis Algoritma - Notasi Asimptotik
PDF
Activity Diagram
PDF
UML dan Use Case View
Materi 8 - Data Mining Association Rule.pdf
Clean Code - Formatting Code
Clean Code - Clean Comments
Clean Code and Design Pattern - Meaningful Names
Model Driven Software Development
Scrum: How to Implement
Pengujian Perangkat Lunak
Data Mining Clustering
Data Mining Klasifikasi (Updated 30 Desember 2020)
Analisis Algoritma - Strategi Algoritma Dynamic Programming
Analisis Algoritma - Strategi Algoritma Divide and Conquer
Analisis Algoritma - Strategi Algoritma Greedy
Analisis Algoritma - Penerapan Strategi Algoritma Brute Force
Analisis Algoritma - Strategi Algoritma Brute Force
Analisis Algoritma - Kelas-kelas Dasar Efisiensi Algoritma
Analisis Algoritma - Teorema Notasi Asimptotik
Analisis Algoritma - Notasi Asimptotik
Activity Diagram
UML dan Use Case View
Ad

Recently uploaded (20)

DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
Microsoft Office 365 Crack Download Free
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
Website Design Services for Small Businesses.pdf
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
most interesting chapter in the world ppt
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
E-Commerce Website Development Companyin india
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
AI Guide for Business Growth - Arna Softech
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Airline CRS | Airline CRS Systems | CRS System
How to Use SharePoint as an ISO-Compliant Document Management System
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Microsoft Office 365 Crack Download Free
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Website Design Services for Small Businesses.pdf
Salesforce Agentforce AI Implementation.pdf
most interesting chapter in the world ppt
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
E-Commerce Website Development Companyin india
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
DNT Brochure 2025 – ISV Solutions @ D365
CCleaner 6.39.11548 Crack 2025 License Key
AI Guide for Business Growth - Arna Softech
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
iTop VPN Crack Latest Version Full Key 2025
GSA Content Generator Crack (2025 Latest)
"Secure File Sharing Solutions on AWS".pptx
Airline CRS | Airline CRS Systems | CRS System

Data Structure (Tree Continued)

  • 3. Types of Tree Traversal • Preorder : Node – Left - Right • Inorder : Left – Node - Right • Postorder : Left – Right - Node
  • 4. Ilustration (1) H A L K B C J Preorder (NLR) : HA KCB JL Inorder (LNR) : HA KCB J L Postorder (LRN) : HA KCB JL
  • 5. Ilustration (2) Preorder (NLR) : ABDE C GH Inorder (LNR) : Postorder (LRN) : A B H CD E F GI I F ABD E CGHI F ABDE CGHI F
  • 6. Case Prefix : / + A- B DH Infix : Postfix: / + ^ - A B F * D * ^ E = A + BDH – F G - K A + B * D^ H- F )( / G( - )E = K H - KG GK-F /+A -B D H* ^ G K-F /+A -BDH *^ GK -F Subtree Kiri Subtree Kanan Root
  • 7. Make binary tree from this general tree and do the tree traversal process: Exercise A B H C D E F GI R P Q
  • 8. TREE TRAVERSAL INTO BINARY TREE 
  • 9. Example 1 Preorder : Inorder : J B H CD E F GI BDEI F GJC H DIEB F CJH G
  • 10. Example 2 Inorder : Postorder : J B H CD E F GI IEDH F CBG J DIEB F CJH G
  • 11. Make binary tree from these result of tree traversal: • Inorder : BCDFGKMPSUWY Preorder : MFDBCKGSPWUY • Postorder : EGHCIMFBNPJLKDA Inorder : EBGCHFMIANJPDLK Exercise
  • 13. Node have 2 Using Preorder Rules : • If scanned node has 2 children then PUSH its right son (RS). • If scanned node hasn’t child then POP element of stack.
  • 14. Node have 2 Using Preorder Notes : • Arrow down (↓) means PUSH. • Arrow up (↑) means POP. • LS : Left Son • RS : Right Son
  • 15. Node have 2 Using Preorder A B H CD E F GI Preorder (NLR) : Head B D E I C F G H A BDEICFGHA LS RS LS RS B RS B LS RS RS RS C RS C
  • 16. Node have 2 Using Inorder Rules and Note : • If scanned node has left child then PUSH itself (Scanned Node Address). • If scanned node hasn’t child then POP element of stack. • Add = Address.
  • 17. Node have 2 Using Inorder A B H CD E F GI Inorder (LNR) : Head B D E I E B C F G DIEBFGHCA LS RS LS Add. B Add. E RS LS Add. C Add. BAdd. E Add. C RS RS H RSC A
  • 18. Node have 2 Using Postorder Rules : • If scanned node has 2 children then PUSH itself (Scanned Node Address) and its right child. • If scanned node has only 1 child then PUSH itself (Scanned Node Address). • If scanned node hasn’t child then POP element of stack.
  • 19. Node have 2 Using Postorder A B H CD E F GI Postorder (LRN) : Head B D E I E D C F G IEDHGFACB LS RS LS RS B Add. E LS RS B Add. D G F A C H Add B RS Add C Add D Add E RS C Add C Add F RS Add G Add G Add F RS C B Add B
  • 20. Traverse this tree using stack (3 ways): Exercise 1 A B H C D E FI
  • 21. Make binary tree from this statement then traverse binary tree using stack (3 ways): Exercise 2 E = A + (B-D)H – F GK
  • 22. Make binary in linked list form from these result of tree traversal and traverse the result using stack in postorder way: Preorder : RFCAEDLHPVTZXWY Inorder : ACDEFHLPRTVWXYZ Exercise 3
  • 23. Make binary tree from this general tree and traverse the result using preorder, inorder, and postorder: Exercise 4 S B L D E F J K MC G H I N P X A PY
  • 24. Contact Person: Adam Mukharil Bachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: adfbipotter@gmail.com Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2012