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
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
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