tReE 
Tenia Wahyuningrum, S.Kom. MT 
www.st3telkom.ac.id
Tree … 
Kumpulan node yang saling 
terhubung satu sama lain 
dalam suatu kesatuan yang 
membentuk layakya struktur sebuah 
pohon. 
Tenia Wahyuningrum www.st3telkom.ac.id
Tree … 
 merepresentasikan suatu struktur 
hirarki (one-to-many) 
 tampak sebagai kumpulan node dari 
atas ke bawah. 
Tenia Wahyuningrum www.st3telkom.ac.id
Tree … 
 salah satu bentuk implementasi 
banyak linked list yang 
digunakan untuk menggambarkan 
hubungan yang bersifat hirarkis 
Tenia Wahyuningrum www.st3telkom.ac.id
Karena harapan lah, kita menanam pohon 
Meskipun kita tahu tak akan memetik buahnya berpuluh-puluh tahun kemudian
Contoh penggunaan struktur 
tree 
Family tree 
Tenia Wahyuningrum www.st3telkom.ac.id
Contoh penggunaan struktur 
tree 
Tournamen schedule 
Tenia Wahyuningrum www.st3telkom.ac.id
Contoh penggunaan struktur 
tree 
Organization Structure 
Tenia Wahyuningrum www.st3telkom.ac.id
Tree anatomy 
R 
S 
T 
X 
Y Z 
Root 
Internal Node 
U V W 
Leaf 
Child of X 
Subtree 
Parent of Z and Y 
Level 0 
Level 1 
Level 2 
Level 3
Terminologi Tree 
Tenia Wahyuningrum www.st3telkom.ac.id
a Tree 
R 
S T 
Ancestor (U) = T, R 
Descendant (T) = U, V, W 
Parent (Y) = S 
Child (R) = S, T 
Sibling (U) = V, W 
Size = 8 
Height = 3 
Root = R 
Leaf = Y, Z, U, V, W 
Degree (T) = 3 
Y Z U V W 
Tenia Wahyuningrum www.st3telkom.ac.id
Representasi Tree 
Tenia Wahyuningrum www.st3telkom.ac.id
Tree Representation 
 Notasi Tingkat 
Tenia Wahyuningrum www.st3telkom.ac.id
Tree Representation 
 Notasi Kurung 
(A(B(D,E(I,J)),C(F,G,H))) 
Tenia Wahyuningrum www.st3telkom.ac.id
Latihan 
• Buat diagram venn, notasi kurung dan 
notasi tingkat! 
X 
Y R S 
Q 
T U W 
Z 
P M 
N 
Tenia Wahyuningrum www.st3telkom.ac.id
• Identifikasikan ! 
 Ancestor (N) = 
 Descendant (Y) = 
 Parent (Z) = 
 Child (Q) = 
 Sibling (U) = 
 Size = 
 Height = 
 Root = 
 Leaf = 
 Degree (R) = 
Tenia Wahyuningrum www.st3telkom.ac.id
Binnary Tree 
Semakin tinggi pohon, semakin kuat angin meniupnya
– Suatu tree dengan syarat bahwa tiap 
node hanya boleh memiliki maksimal dua 
subtree dan kedua subtree tersebut harus 
terpisah. 
– Tiap node dalam binary tree hanya boleh 
memiliki paling banyak dua child. 
Tenia Wahyuningrum www.st3telkom.ac.id
Binary Tree 
Tenia Wahyuningrum www.st3telkom.ac.id
Binary Tree 
A 
B C 
D E F G 
Tenia Wahyuningrum www.st3telkom.ac.id
A 
Binary Tree 
B C 
D E 
Tenia Wahyuningrum www.st3telkom.ac.id
Binary Tree 
A 
D 
B E 
C F 
Tenia Wahyuningrum www.st3telkom.ac.id
Node pada Binary Tree 
 Jumlah maksimum node pada setiap 
tingkat adalah 2n 
 Node pada binary tree maksimum 
berjumlah 2n-1 
Tenia Wahyuningrum www.st3telkom.ac.id
Node pada Binary Tree 
A 
B C 
D E F G 
Tingkat ke-0, jumlah max = 20 
Tingkat ke-1, jumlah max = 21 
Tingkat ke-2, jumlah max = 22 
Tenia Wahyuningrum www.st3telkom.ac.id
Latihan 
• Gambarkan pohon biner dengan 
ketentuan sbb : 
 Ancestor (M) = Z, X 
 Descendant (Y) = K, L 
 Parent (N) = Z 
 Child (Z) = M, N 
 Sibling (Y) = Z 
 Size = 7 
 Height = 3 
 Root = X 
 Leaf = K, L, M, N 
Tenia Wahyuningrum www.st3telkom.ac.id
xxx 
Penelusuran Pohon Biner 
Jika kau teriaki dan maki pohon, lambat laun pohon akan mati 
Tenia Wahyuningrum www.st3telkom.ac.id
Definisi 
• Penelusuran seluruh node pada binary 
tree. 
• Metode : 
–Preorder 
–Inorder 
–Postorder 
Tenia Wahyuningrum www.st3telkom.ac.id
PreOrder Traversal 
1. Cetak data pada root 
2. Secara rekursif mencetak seluruh data 
pada subpohon kiri 
3. Secara rekursif mencetak seluruh data 
pada subpohon kanan 
Tenia Wahyuningrum www.st3telkom.ac.id
Preorder Example (visit = 
print) 
a 
b c 
a b c 
Tenia Wahyuningrum www.st3telkom.ac.id
Preorder Example (visit = 
print) 
a 
b c 
d e 
f 
g h i j 
a b d g h e i c f j 
Tenia Wahyuningrum www.st3telkom.ac.id
Preorder Of Expression Tree 
+ 
a b 
- 
c d 
+ 
e f 
* 
/ 
/ * + a b - c d + e f 
Gives prefix form of expression! 
Tenia Wahyuningrum www.st3telkom.ac.id
InOrder Traversal 
1.Secara rekursif mencetak seluruh data 
pada subpohon kiri 
2.Cetak data pada root 
3.Secara rekursif mencetak seluruh data 
pada subpohon kanan 
Tenia Wahyuningrum www.st3telkom.ac.id
Inorder Example (visit = print) 
a 
b c 
b a c 
Tenia Wahyuningrum www.st3telkom.ac.id
Inorder Example (visit = print) 
a 
b c 
d e 
f 
g h i j 
g d h b e i a f j c 
Tenia Wahyuningrum www.st3telkom.ac.id
Postorder Traversal 
1.Secara rekursif mencetak seluruh data 
pada subpohon kiri 
2.Secara rekursif mencetak seluruh data 
pada subpohon kanan 
3.Cetak data pada root 
Tenia Wahyuningrum www.st3telkom.ac.id
Postorder Example (visit = 
print) 
a 
b c 
b c a 
Tenia Wahyuningrum www.st3telkom.ac.id
Postorder Example (visit = 
print) a 
b c 
d e 
f 
g h i j 
g h d i e b j f c a 
Tenia Wahyuningrum www.st3telkom.ac.id
Postorder Of Expression Tree 
+ 
a b 
- 
c d 
+ 
e f 
* 
/ 
a b + c d - * e f + / 
Gives postfix form of expression! 
Tenia Wahyuningrum www.st3telkom.ac.id
Latihan 
• Telusuri pohon biner berikut dengan 
menggunakan metode pre, in, post ! 
Tenia Wahyuningrum www.st3telkom.ac.id
Latihan 1 
+ 
* 
3 5 
- 
2 / 
8 4 
Tenia Wahyuningrum www.st3telkom.ac.id
Latihan 2 
2 
7 5 
2 6 9 
5 11 4 
Tenia Wahyuningrum www.st3telkom.ac.id
Tree

Tree

  • 1.
    tReE Tenia Wahyuningrum,S.Kom. MT www.st3telkom.ac.id
  • 2.
    Tree … Kumpulannode yang saling terhubung satu sama lain dalam suatu kesatuan yang membentuk layakya struktur sebuah pohon. Tenia Wahyuningrum www.st3telkom.ac.id
  • 3.
    Tree … merepresentasikan suatu struktur hirarki (one-to-many)  tampak sebagai kumpulan node dari atas ke bawah. Tenia Wahyuningrum www.st3telkom.ac.id
  • 4.
    Tree … salah satu bentuk implementasi banyak linked list yang digunakan untuk menggambarkan hubungan yang bersifat hirarkis Tenia Wahyuningrum www.st3telkom.ac.id
  • 5.
    Karena harapan lah,kita menanam pohon Meskipun kita tahu tak akan memetik buahnya berpuluh-puluh tahun kemudian
  • 6.
    Contoh penggunaan struktur tree Family tree Tenia Wahyuningrum www.st3telkom.ac.id
  • 7.
    Contoh penggunaan struktur tree Tournamen schedule Tenia Wahyuningrum www.st3telkom.ac.id
  • 8.
    Contoh penggunaan struktur tree Organization Structure Tenia Wahyuningrum www.st3telkom.ac.id
  • 9.
    Tree anatomy R S T X Y Z Root Internal Node U V W Leaf Child of X Subtree Parent of Z and Y Level 0 Level 1 Level 2 Level 3
  • 10.
    Terminologi Tree TeniaWahyuningrum www.st3telkom.ac.id
  • 11.
    a Tree R S T Ancestor (U) = T, R Descendant (T) = U, V, W Parent (Y) = S Child (R) = S, T Sibling (U) = V, W Size = 8 Height = 3 Root = R Leaf = Y, Z, U, V, W Degree (T) = 3 Y Z U V W Tenia Wahyuningrum www.st3telkom.ac.id
  • 12.
    Representasi Tree TeniaWahyuningrum www.st3telkom.ac.id
  • 13.
    Tree Representation Notasi Tingkat Tenia Wahyuningrum www.st3telkom.ac.id
  • 14.
    Tree Representation Notasi Kurung (A(B(D,E(I,J)),C(F,G,H))) Tenia Wahyuningrum www.st3telkom.ac.id
  • 15.
    Latihan • Buatdiagram venn, notasi kurung dan notasi tingkat! X Y R S Q T U W Z P M N Tenia Wahyuningrum www.st3telkom.ac.id
  • 16.
    • Identifikasikan !  Ancestor (N) =  Descendant (Y) =  Parent (Z) =  Child (Q) =  Sibling (U) =  Size =  Height =  Root =  Leaf =  Degree (R) = Tenia Wahyuningrum www.st3telkom.ac.id
  • 17.
    Binnary Tree Semakintinggi pohon, semakin kuat angin meniupnya
  • 18.
    – Suatu treedengan syarat bahwa tiap node hanya boleh memiliki maksimal dua subtree dan kedua subtree tersebut harus terpisah. – Tiap node dalam binary tree hanya boleh memiliki paling banyak dua child. Tenia Wahyuningrum www.st3telkom.ac.id
  • 19.
    Binary Tree TeniaWahyuningrum www.st3telkom.ac.id
  • 20.
    Binary Tree A B C D E F G Tenia Wahyuningrum www.st3telkom.ac.id
  • 21.
    A Binary Tree B C D E Tenia Wahyuningrum www.st3telkom.ac.id
  • 22.
    Binary Tree A D B E C F Tenia Wahyuningrum www.st3telkom.ac.id
  • 23.
    Node pada BinaryTree  Jumlah maksimum node pada setiap tingkat adalah 2n  Node pada binary tree maksimum berjumlah 2n-1 Tenia Wahyuningrum www.st3telkom.ac.id
  • 24.
    Node pada BinaryTree A B C D E F G Tingkat ke-0, jumlah max = 20 Tingkat ke-1, jumlah max = 21 Tingkat ke-2, jumlah max = 22 Tenia Wahyuningrum www.st3telkom.ac.id
  • 25.
    Latihan • Gambarkanpohon biner dengan ketentuan sbb :  Ancestor (M) = Z, X  Descendant (Y) = K, L  Parent (N) = Z  Child (Z) = M, N  Sibling (Y) = Z  Size = 7  Height = 3  Root = X  Leaf = K, L, M, N Tenia Wahyuningrum www.st3telkom.ac.id
  • 26.
    xxx Penelusuran PohonBiner Jika kau teriaki dan maki pohon, lambat laun pohon akan mati Tenia Wahyuningrum www.st3telkom.ac.id
  • 27.
    Definisi • Penelusuranseluruh node pada binary tree. • Metode : –Preorder –Inorder –Postorder Tenia Wahyuningrum www.st3telkom.ac.id
  • 28.
    PreOrder Traversal 1.Cetak data pada root 2. Secara rekursif mencetak seluruh data pada subpohon kiri 3. Secara rekursif mencetak seluruh data pada subpohon kanan Tenia Wahyuningrum www.st3telkom.ac.id
  • 29.
    Preorder Example (visit= print) a b c a b c Tenia Wahyuningrum www.st3telkom.ac.id
  • 30.
    Preorder Example (visit= print) a b c d e f g h i j a b d g h e i c f j Tenia Wahyuningrum www.st3telkom.ac.id
  • 31.
    Preorder Of ExpressionTree + a b - c d + e f * / / * + a b - c d + e f Gives prefix form of expression! Tenia Wahyuningrum www.st3telkom.ac.id
  • 32.
    InOrder Traversal 1.Secararekursif mencetak seluruh data pada subpohon kiri 2.Cetak data pada root 3.Secara rekursif mencetak seluruh data pada subpohon kanan Tenia Wahyuningrum www.st3telkom.ac.id
  • 33.
    Inorder Example (visit= print) a b c b a c Tenia Wahyuningrum www.st3telkom.ac.id
  • 34.
    Inorder Example (visit= print) a b c d e f g h i j g d h b e i a f j c Tenia Wahyuningrum www.st3telkom.ac.id
  • 35.
    Postorder Traversal 1.Secararekursif mencetak seluruh data pada subpohon kiri 2.Secara rekursif mencetak seluruh data pada subpohon kanan 3.Cetak data pada root Tenia Wahyuningrum www.st3telkom.ac.id
  • 36.
    Postorder Example (visit= print) a b c b c a Tenia Wahyuningrum www.st3telkom.ac.id
  • 37.
    Postorder Example (visit= print) a b c d e f g h i j g h d i e b j f c a Tenia Wahyuningrum www.st3telkom.ac.id
  • 38.
    Postorder Of ExpressionTree + a b - c d + e f * / a b + c d - * e f + / Gives postfix form of expression! Tenia Wahyuningrum www.st3telkom.ac.id
  • 39.
    Latihan • Telusuripohon biner berikut dengan menggunakan metode pre, in, post ! Tenia Wahyuningrum www.st3telkom.ac.id
  • 40.
    Latihan 1 + * 3 5 - 2 / 8 4 Tenia Wahyuningrum www.st3telkom.ac.id
  • 41.
    Latihan 2 2 7 5 2 6 9 5 11 4 Tenia Wahyuningrum www.st3telkom.ac.id