20200720215529D5797 - 20180725180147D5542 - COMP6049 Pert 5
20200720215529D5797 - 20180725180147D5542 - COMP6049 Pert 5
20200720215529D5797 - 20180725180147D5542 - COMP6049 Pert 5
and Analysis
Topic 5 – Analysis of Data Structures: Stack, Queue, Tree, and
Binary Tree
Outline Materials
• Definition of tree
• Tree traversal
• Binary tree characteristics
• Operations in tree
• Example of ADT
– Stack
– Queue
– Tree
– Graph
STACK
Bina Nusantara
OPERATION OF STACK
Bina Nusantara
ILLUSTRATION OF STACK
Bina Nusantara
QUEUE
Bina Nusantara
OPERATION OF QUEUE
Bina Nusantara
ILLUSTRATION OF QUEUE
Bina Nusantara
CIRCULAR ADT
Tail Head
ln l 1
l2
l3
Bina Nusantara
COMPARISON
Bina Nusantara
TREE
Bina Nusantara
TREE ILLUSTRATIONS
Bina Nusantara
BINARY TREE (1)
k = 2k-1
Bina Nusantara
BINARY TREE (2)
Bina Nusantara
BINARY TREE ILLUSTRATIONS
Bina Nusantara
TREE TRAVERSAL
• Such traversals are classified by the order in which the nodes are
visited.
– Pre-order Traversal
• parent–left–right
– Level-order Traversal
• parent–left–right (each level)
– In-order Traversal
• left–parent–right
– Post-order Traversal
• left–right–parent
Bina Nusantara
BINARY TREE TRAVERSAL
• Pre-order : F, B, A, D, C, E, G, I, H
• In-order : A, B, C, D, E, F, G, H, I
• Post-order : A, C, E, D, B, H, I, G, F
• Level-order : F, B, G, A, D, I, C, E, H
Bina Nusantara
EULER TOUR TRAVERSAL
+
1
16
10 11
x x
2 12
9 15
4
3 13 14
2 – 3 b
5
8
7 Arithmetic Expression Tree
6 2 x (a – 1) + (3 x b)
a 1
Bina Nusantara
EXERCISE
Bina Nusantara
EXERCISE
Bina Nusantara
REVIEW
• Stack definition
• Stack operation
• Stack implementation
• Queue definition
• Queue operation
• Queue implementation
• Circular Queue
• Tree
• Binary tree
• Binary tree traversal
Bina Nusantara
REVIEW
• Tree
• Binary tree
• Binary tree traversal
Q&A
References